	/* MOS                                                        */
/* Giordano Mion, Luca David Opromolla and Alessandro Sforza  */
/* University of Sussex, Banco de Portugal & NC State, and Bologna       */


program drop _all
clear all
capture log close
set more off
local path = "/Users/lucadavidopromolla/Projects/MOS_rev"
cd "`path'/results"
log using "`path'/logs/MOS_new_stuff_Apr_27_2022_rev.log", replace



//////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Step 1. Table 2 using log revenues as a measure of firm size (instead of log number of employees).  //
//////////////////////////////////////////////////////////////////////////////////////////////////////////


// Locals
local instruct "tex(pretty frag) tdec(3) rdec(3) auto(3) bdec(3) sdec(3) symbol($^a$,$^b$,$^c$) se label  e(N) nocons"
local ctr_exp_mf = "relsize relapp_lbprod ln_firmage foreign lnod sh_skilled sh_skilled_d relmean_age relsd_age relmean_educ relsd_educ"
local y "y1999 y2000 y2002 y2003 y2004 y2005"
local inta2002 "inta_bf2002"
local inta "inta2002 inta2003 inta2004 inta2005"
local inta_sim "inta20023 inta20045"
local linta_sim "linta20023 linta20045"
local l2inta_sim "l2inta20023 l2inta20045"
local l3inta_sim "l3inta20023 l3inta20045"
local linta "linta2002 linta2003 linta2004 linta2005"
local linta2002 "linta_bf2002"
local linta2002_ang "linta_bf2002_ang"
local y_ang "y1998_ang y1999_ang y2000_ang y2002_ang y2003_ang y2004_ang y2005_ang"
local inta_ang "inta2002_ang inta2003_ang inta2004_ang inta2005_ang"
local linta_ang "linta2002_ang linta2003_ang linta2004_ang linta2005_ang"
local l2inta "l2inta2002 l2inta2003 l2inta2004 l2inta2005"
local l2inta2002 "l2inta_bf2002"
local l2inta2002_ang "l2inta_bf2002_ang"
local l2inta_ang "l2inta2002_ang l2inta2003_ang l2inta2004_ang l2inta2005_ang"
local l3inta "l3inta2002 l3inta2003 l3inta2004 l3inta2005"
local l3inta2002 "l3inta_bf2002"
local l3inta2002_ang "l3inta_bf2002_ang"
local l3inta_ang "l3inta2002_ang l3inta2003_ang l3inta2004_ang l3inta2005_ang"
local winta2002 "winta_bf2002"
local winta "winta2002 winta2003 winta2004 winta2005"
local lwinta "lwinta2002 lwinta2003 lwinta2004 lwinta2005"
local l2winta "l2winta2002 l2winta2003 l2winta2004 l2winta2005"
local l3winta "l3winta2002 l3winta2003 l3winta2004 l3winta2005"
local inta2002_ang "inta_bf2002_ang"


// A. Destination experience

// Full-history experience

// A1. Having a manager with export experience to Angola
use "`path'/computation/data_ang.dta",clear
replace relsize = log(vendas_euro)
keep if ano>=1998 & ano<=2005
reg entry mkt_spec_exp `y' `ctr_exp_mf' i.nace,  vce(cluster empresa)
estat summarize
outreg2 using tables/table1dw_ba_sr.xls, ctitle(OLS) addtext("Firm-time controls", X, "Year FE", X, "Industry FE", X, "Estimation Method", "OLS") `instruct' replace keep(mkt_spec_exp) 
outreg2 using tables/table1dw_ctr_ba_sr.xls, ctitle(OLS) `instruct' replace keep(`ctr_exp_mf' `y')

use "`path'/computation/data_ang.dta",clear
replace relsize = log(vendas_euro)
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
reg entry_bs mkt_spec_exp `y' `ctr_exp_mf' i.nace,  vce(cluster empresa)
estat summarize
outreg2 using tables/table1dw_bsample_ba_sr.xls, ctitle(OLS) addtext("Firm-time controls", X, "Year FE", X, "Industry FE", X, "Estimation Method", "OLS") `instruct' replace keep(mkt_spec_exp) 
outreg2 using tables/table1dw_ctr_bsample_ba_sr.xls, ctitle(OLS) `instruct' replace keep(`ctr_exp_mf' `y')

// A2. Placebo: effect of export experience before the end of the war
use "`path'/computation/data_ang.dta",clear
replace relsize = log(vendas_euro)
keep if ano>=1998 & ano<=2005
reghdfe entry mkt_spec_exp `y' `inta' `ctr_exp_mf', absorb(empresa) vce(cluster empresa) tol(0.001)
outreg2 using tables/table1dw_ba_sr.xls, ctitle("Placebo") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_ba_sr.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

use "`path'/computation/data_ang.dta",clear
replace relsize = log(vendas_euro)
keep if ano>=1998 & ano<=2005
reghdfe entry mkt_spec_exp `y' `inta2002' `ctr_exp_mf', absorb(empresa) vce(cluster empresa) tol(0.001)
outreg2 using tables/table1dw_ba_sr.xls, ctitle("Placebo") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_ba_sr.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

use "`path'/computation/data_ang.dta",clear
replace relsize = log(vendas_euro)
keep if ano>=1998 & ano<=2005
reg entry mkt_spec_exp `y' `inta' `ctr_exp_mf', vce(cluster empresa)
outreg2 using tables/table1dw_ba_sr.xls, ctitle("Placebo") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_ba_sr.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

use "`path'/computation/data_ang.dta",clear
replace relsize = log(vendas_euro)
keep if ano>=1998 & ano<=2005
reg entry mkt_spec_exp `y' `inta2002' `ctr_exp_mf', vce(cluster empresa)
outreg2 using tables/table1dw_ba_sr.xls, ctitle("Placebo") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_ba_sr.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize


use "`path'/computation/data_ang.dta",clear
replace relsize = log(vendas_euro)
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
reghdfe entry_bs mkt_spec_exp `y' `inta' `ctr_exp_mf', absorb(empresa) vce(cluster empresa) tol(0.001)
outreg2 using tables/table1dw_bsample_ba_sr.xls, ctitle("Placebo") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_bsample_ba_sr.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

use "`path'/computation/data_ang.dta",clear
replace relsize = log(vendas_euro)
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
reghdfe entry_bs mkt_spec_exp `y' `inta2002' `ctr_exp_mf', absorb(empresa) vce(cluster empresa) tol(0.001)
outreg2 using tables/table1dw_bsample_ba_sr.xls, ctitle("Placebo") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_bsample_ba_sr.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

use "`path'/computation/data_ang.dta",clear
replace relsize = log(vendas_euro)
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
reg entry_bs mkt_spec_exp `y' `inta' `ctr_exp_mf', vce(cluster empresa)
outreg2 using tables/table1dw_bsample_ba_sr.xls, ctitle("Placebo") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_bsample_ba_sr.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

use "`path'/computation/data_ang.dta",clear
replace relsize = log(vendas_euro)
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
reg entry_bs mkt_spec_exp `y' `inta2002' `ctr_exp_mf', vce(cluster empresa)
outreg2 using tables/table1dw_bsample_ba_sr.xls, ctitle("Placebo") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_bsample_ba_sr.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize


// A3. Placebo: IV

use "`path'/computation/data_ang.dta",clear
replace relsize = log(vendas_euro)
keep if ano>=1998 & ano<=2005
xtivreg2 entry (mkt_spec_exp `inta' = l3mkt_spec_exp `l3inta' l2mkt_spec_exp `l2inta' lmkt_spec_exp `linta') y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',fe  cluster(empresa) first
outreg2 using tables/table1dw_ba_sr.xls, ctitle("Placebo IV") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_ba_sr.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize


use "`path'/computation/data_ang.dta",clear
replace relsize = log(vendas_euro)
keep if ano>=1998 & ano<=2005
su entry mkt_spec_exp `inta2002'  l3mkt_spec_exp `l3inta2002' l2mkt_spec_exp `l2inta2002' lmkt_spec_exp `linta2002' y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf' if ano==2002
xtivreg2 entry (mkt_spec_exp `inta2002' = l3mkt_spec_exp `l3inta2002' l2mkt_spec_exp `l2inta2002' lmkt_spec_exp `linta2002') y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',fe  cluster(empresa) first partial(y1999 y2000 y2002 y2003 y2004 y2005)
outreg2 using tables/table1dw_ba_sr.xls, ctitle("Placebo IV") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_ba_sr.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize


use "`path'/computation/data_ang.dta",clear
replace relsize = log(vendas_euro)
keep if ano>=1998 & ano<=2005
ivreg2 entry (mkt_spec_exp `inta' = l3mkt_spec_exp `l3inta' l2mkt_spec_exp `l2inta' lmkt_spec_exp `linta') y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',  cluster(empresa) first
outreg2 using tables/table1dw_ba_sr.xls, ctitle("Placebo IV") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_ba_sr.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize


use "`path'/computation/data_ang.dta",clear
replace relsize = log(vendas_euro)
keep if ano>=1998 & ano<=2005
ivreg2 entry (mkt_spec_exp `inta2002' = l3mkt_spec_exp `l3inta2002' l2mkt_spec_exp `l2inta2002' lmkt_spec_exp `linta2002') y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',  cluster(empresa) first
outreg2 using tables/table1dw_ba_sr.xls, ctitle("Placebo IV") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_ba_sr.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize



use "`path'/computation/data_ang.dta",clear
replace relsize = log(vendas_euro)
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
xtivreg2 entry_bs (mkt_spec_exp `inta' = l3mkt_spec_exp `l3inta' l2mkt_spec_exp `l2inta' lmkt_spec_exp `linta') y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',fe  cluster(empresa) first
outreg2 using tables/table1dw_bsample_ba_sr.xls, ctitle("Placebo IV") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_bsample_ba_sr.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize


use "`path'/computation/data_ang.dta",clear
replace relsize = log(vendas_euro)
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
xtivreg2 entry_bs (mkt_spec_exp `inta2002' = l3mkt_spec_exp `l3inta2002' l2mkt_spec_exp `l2inta2002' lmkt_spec_exp `linta2002') y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',fe  cluster(empresa) first
outreg2 using tables/table1dw_bsample_ba_sr.xls, ctitle("Placebo IV") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_bsample_ba_sr.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize


use "`path'/computation/data_ang.dta",clear
replace relsize = log(vendas_euro)
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
ivreg2 entry_bs (mkt_spec_exp `inta' = l3mkt_spec_exp `l3inta' l2mkt_spec_exp `l2inta' lmkt_spec_exp `linta') y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',  cluster(empresa) first
outreg2 using tables/table1dw_bsample_ba_sr.xls, ctitle("Placebo IV") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_bsample_ba_sr.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

use "`path'/computation/data_ang.dta",clear
replace relsize = log(vendas_euro)
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
ivreg2 entry_bs (mkt_spec_exp `inta2002' = l3mkt_spec_exp `l3inta2002' l2mkt_spec_exp `l2inta2002' lmkt_spec_exp `linta2002') y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',  cluster(empresa) first
outreg2 using tables/table1dw_bsample_ba_sr.xls, ctitle("Placebo IV") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_bsample_ba_sr.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize


///////////////////////////////////////////////////////////////////////////////////////////////////////
//  Step 2. Average exports from 2002 to 2005 of those firms that start exporting to Angola in 2002  //
//          (and of the subset that has a manager with export experience to Angola in 2002 
///////////////////////////////////////////////////////////////////////////////////////////////////////

use "`path'/computation/MMT_trade_status_entryb_basic",clear
sort empresa dest ano
gen entry = (de_==1 & de_[_n-1]==0 & empresa==empresa[_n-1] & dest==dest[_n-1] & other_exporter==0) // Keep only period in which the 
keep if ano>=2002 & ano<=2005
keep if dest>=1 & dest<=14
egen double t4_exp = sum(v_est_),by(empresa dest)
egen double tot_exp = sum(v_est_),by(empresa ano)
keep if entry==1
keep if dest==8
keep if ano==2002
keep empresa ano t4_exp mkt_spec_exp vendas_euro tot_exp
collapse (mean) vendas_euro t4_exp tot_exp,by(empresa)
//collapse (count) nfirms=t4_exp (sum) t4_exp vendas_euro tot_exp (mean) mean_exp4=t4_exp mean_sal=vendas_euro mean_exp=tot_exp (p50) p50_exp4=t4_exp p50_sal=vendas_euro p50_tot_exp=tot_exp,by(mkt_spec_exp)
collapse (count) nfirms=t4_exp (sum) t4_exp vendas_euro tot_exp (mean) mean_exp4=t4_exp mean_sal=vendas_euro mean_exp=tot_exp (p50) p50_exp4=t4_exp p50_sal=vendas_euro p50_tot_exp=tot_exp
l
gen double ravg_expang_sal = mean_exp4/mean_sal
gen double ravg_expang_exp = mean_exp4/mean_exp
gen double r50_expang_sal = p50_exp4/p50_sal
gen double r50_expang_exp = p50_exp4/p50_tot_exp
l ravg* r50*


//////////////////////////////////////////////////////////////////
//  Step 3. Figures to compare control and treated firms        //
//////////////////////////////////////////////////////////////////

use "`path'/computation/ang.dta",clear
gen od = dest!=8 & dest>=1 & dest<=14 & de_==1
egen nod = sum(od),by(empresa ano)
sort dest empresa ano
gen lnod = nod[_n-1] if empresa==empresa[_n-1] & dest==dest[_n-1]
local ctr_exp_mf = "relsize relapp_lbprod ln_firmage foreign lnod sh_skilled sh_skilled_d relmean_age relsd_age relmean_educ relsd_educ"
marksample regsample
markout `regsample' `ctr_exp_mf' mkt_spec_exp ano  // Deflating variables
keep if `regsample'==1
sort empresa dest ano
keep if (de_[_n-1]==0 & empresa==empresa[_n-1] & dest==dest[_n-1] & other_exporter==0)
keep if dest==8
keep if ano==2000 | ano==2002
gen mg_exp_AO_2002 = 1 if mkt_spec_exp==1 & ano==2002
replace mg_exp_AO_2002 = 0 if mkt_spec_exp==0 & ano==2002
egen mg_exp_AO_2002_m = max(mg_exp_AO_2002),by(empresa)
save rt_sample1,replace
local path = "/Users/lucadavidopromolla/Projects/MOS_rev"
use "`path'/computation/ang.dta",clear
sort empresa dest ano
gen entry = (de_==1 & de_[_n-1]==0 & empresa==empresa[_n-1] & dest==dest[_n-1] & other_exporter==0)
keep if dest==8
keep if ano>=1998 & ano<=2005
collapse (max) entry,by(empresa)
keep if entry==1
keep empresa
sort empresa
merge 1:m empresa using rt_sample1
keep if _merge==3
save rt_sample2,replace
// Specifications without fixed effects
// Size in 2002
use rt_sample1,clear
kdensity relsize if mg_exp_AO_2002_m==0 & ano==2002, gen(x_nia y_nia) nograph
kdensity relsize if mg_exp_AO_2002_m==1 & ano==2002, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm size in 2002",size(small)) saving(graphs/rt_size_2002.gph,replace))      
graph export "graphs/rt_size_2002.png", as(png) replace
reg relsize mg_exp_AO_2002_m if ano==2002
drop x_ia x_nia y_ia y_nia
// Size in 2000
kdensity relsize if mg_exp_AO_2002_m==0 & ano==2000, gen(x_nia y_nia) nograph
kdensity relsize if mg_exp_AO_2002_m==1 & ano==2000, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm size in 2000",size(small)) saving(graphs/rt_size_2000.gph,replace))      
graph export "graphs/rt_size_2000.png", as(png) replace
reg relsize mg_exp_AO_2002_m if ano==2000
drop x_ia x_nia y_ia y_nia
// Productivity in 2002
kdensity relapp_lbprod if mg_exp_AO_2002_m==0 & ano==2002, gen(x_nia y_nia) nograph
kdensity relapp_lbprod if mg_exp_AO_2002_m==1 & ano==2002, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm productivity in 2002",size(small)) saving(graphs/rt_prod_2002.gph,replace))      
graph export "graphs/rt_prod_2002.png", as(png) replace
reg relapp_lbprod mg_exp_AO_2002_m if ano==2002
drop x_ia x_nia y_ia y_nia
// Productivity in 2000
kdensity relapp_lbprod if mg_exp_AO_2002_m==0 & ano==2000, gen(x_nia y_nia) nograph
kdensity relapp_lbprod if mg_exp_AO_2002_m==1 & ano==2000, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm productivity in 2000",size(small)) saving(graphs/rt_prod_2000.gph,replace))      
graph export "graphs/rt_prod_2000.png", as(png) replace
reg relapp_lbprod mg_exp_AO_2002_m if ano==2000
drop x_ia x_nia y_ia y_nia
// Number of export destinations in 2002
kdensity lnod if mg_exp_AO_2002_m==0 & ano==2002, gen(x_nia y_nia) nograph
kdensity lnod if mg_exp_AO_2002_m==1 & ano==2002, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm number of export destinations in 2002",size(small)) saving(graphs/rt_lnod_2002.gph,replace))      
graph export "graphs/rt_lnod_2002.png", as(png) replace
reg lnod mg_exp_AO_2002_m if ano==2002
drop x_ia x_nia y_ia y_nia
// Number of export destinations in 2000
kdensity lnod if mg_exp_AO_2002_m==0 & ano==2000, gen(x_nia y_nia) nograph
kdensity lnod if mg_exp_AO_2002_m==1 & ano==2000, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm number of export destinations in 2000",size(small)) saving(graphs/rt_lnod_2000.gph,replace))      
graph export "graphs/rt_lnod_2000.png", as(png) replace
reg lnod mg_exp_AO_2002_m if ano==2000
drop x_ia x_nia y_ia y_nia
// Share of skilled workers in 2002
kdensity sh_skilled if mg_exp_AO_2002_m==0 & ano==2002, gen(x_nia y_nia) nograph
kdensity sh_skilled if mg_exp_AO_2002_m==1 & ano==2002, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm share of skilled worker in 2002",size(small)) saving(graphs/rt_sh_2002.gph,replace))      
graph export "graphs/rt_sh_2002.png", as(png) replace
reg sh_skilled mg_exp_AO_2002_m if ano==2002
drop x_ia x_nia y_ia y_nia
// Share of skilled workers in 2000
kdensity sh_skilled if mg_exp_AO_2002_m==0 & ano==2000, gen(x_nia y_nia) nograph
kdensity sh_skilled if mg_exp_AO_2002_m==1 & ano==2000, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm share of skilled worker in 2000",size(small)) saving(graphs/rt_sh_2000.gph,replace))      
graph export "graphs/rt_sh_2000.png", as(png) replace
reg sh_skilled mg_exp_AO_2002_m if ano==2000
drop x_ia x_nia y_ia y_nia
// (log) firm age) in 2002
kdensity ln_firmage if mg_exp_AO_2002_m==0 & ano==2002, gen(x_nia y_nia) nograph
kdensity ln_firmage if mg_exp_AO_2002_m==1 & ano==2002, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("(Log) firm age in 2002",size(small)) saving(graphs/rt_fa_2002.gph,replace))      
graph export "graphs/rt_fa_2002.png", as(png) replace
reg ln_firmage mg_exp_AO_2002_m if ano==2002
drop x_ia x_nia y_ia y_nia
// (log) firm age) in 2000
kdensity ln_firmage if mg_exp_AO_2002_m==0 & ano==2000, gen(x_nia y_nia) nograph
kdensity ln_firmage if mg_exp_AO_2002_m==1 & ano==2000, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("(Log) firm age in 2000",size(small)) saving(graphs/rt_fa_2000.gph,replace))      
graph export "graphs/rt_fa_2000.png", as(png) replace
reg ln_firmage mg_exp_AO_2002_m if ano==2000
drop x_ia x_nia y_ia y_nia
// Foreign ownership in 2002
reg foreign mg_exp_AO_2002_m if ano==2002
// Foreign ownership in 2000
reg foreign mg_exp_AO_2002_m if ano==2000

// Specifications with fixed effects
// Size in 2002
use rt_sample2,clear
kdensity relsize if mg_exp_AO_2002_m==0 & ano==2002, gen(x_nia y_nia) nograph
kdensity relsize if mg_exp_AO_2002_m==1 & ano==2002, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm size in 2002",size(small)) saving(graphs/rt_size_2002_fe.gph,replace))      
graph export "graphs/rt_size_2002_fe.png", as(png) replace
reg relsize mg_exp_AO_2002_m if ano==2002
drop x_ia x_nia y_ia y_nia
// Size in 2000
kdensity relsize if mg_exp_AO_2002_m==0 & ano==2000, gen(x_nia y_nia) nograph
kdensity relsize if mg_exp_AO_2002_m==1 & ano==2000, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm size in 2000",size(small)) saving(graphs/rt_size_2000_fe.gph,replace))      
graph export "graphs/rt_size_2000_fe.png", as(png) replace
reg relsize mg_exp_AO_2002_m if ano==2000
drop x_ia x_nia y_ia y_nia
// Productivity in 2002
kdensity relapp_lbprod if mg_exp_AO_2002_m==0 & ano==2002, gen(x_nia y_nia) nograph
kdensity relapp_lbprod if mg_exp_AO_2002_m==1 & ano==2002, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm productivity in 2002",size(small)) saving(graphs/rt_prod_2002_fe.gph,replace))      
graph export "graphs/rt_prod_2002_fe.png", as(png) replace
reg relapp_lbprod mg_exp_AO_2002_m if ano==2002
drop x_ia x_nia y_ia y_nia
// Productivity in 2000
kdensity relapp_lbprod if mg_exp_AO_2002_m==0 & ano==2000, gen(x_nia y_nia) nograph
kdensity relapp_lbprod if mg_exp_AO_2002_m==1 & ano==2000, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm productivity in 2000",size(small)) saving(graphs/rt_prod_2000_fe.gph,replace))      
graph export "graphs/rt_prod_2000_fe.png", as(png) replace
reg relapp_lbprod mg_exp_AO_2002_m if ano==2000
drop x_ia x_nia y_ia y_nia
// Number of export destinations in 2002
kdensity lnod if mg_exp_AO_2002_m==0 & ano==2002, gen(x_nia y_nia) nograph
kdensity lnod if mg_exp_AO_2002_m==1 & ano==2002, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm number of export destinations in 2002",size(small)) saving(graphs/rt_lnod_2002_fe.gph,replace))      
graph export "graphs/rt_lnod_2002_fe.png", as(png) replace
reg lnod mg_exp_AO_2002_m if ano==2002
drop x_ia x_nia y_ia y_nia
// Number of export destinations in 2000
kdensity lnod if mg_exp_AO_2002_m==0 & ano==2000, gen(x_nia y_nia) nograph
kdensity lnod if mg_exp_AO_2002_m==1 & ano==2000, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm number of export destinations in 2000",size(small)) saving(graphs/rt_lnod_2000_fe.gph,replace))      
graph export "graphs/rt_lnod_2000_fe.png", as(png) replace
reg lnod mg_exp_AO_2002_m if ano==2000
drop x_ia x_nia y_ia y_nia
// Share of skilled workers in 2002
kdensity sh_skilled if mg_exp_AO_2002_m==0 & ano==2002, gen(x_nia y_nia) nograph
kdensity sh_skilled if mg_exp_AO_2002_m==1 & ano==2002, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm share of skilled worker in 2002",size(small)) saving(graphs/rt_sh_2002_fe.gph,replace))      
graph export "graphs/rt_sh_2002_fe.png", as(png) replace
reg sh_skilled mg_exp_AO_2002_m if ano==2002
drop x_ia x_nia y_ia y_nia
// Share of skilled workers in 2000
kdensity sh_skilled if mg_exp_AO_2002_m==0 & ano==2000, gen(x_nia y_nia) nograph
kdensity sh_skilled if mg_exp_AO_2002_m==1 & ano==2000, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm share of skilled worker in 2000",size(small)) saving(graphs/rt_sh_2000_fe.gph,replace))      
graph export "graphs/rt_sh_2000_fe.png", as(png) replace
reg sh_skilled mg_exp_AO_2002_m if ano==2000
drop x_ia x_nia y_ia y_nia
// (log) firm age) in 2002
kdensity ln_firmage if mg_exp_AO_2002_m==0 & ano==2002, gen(x_nia y_nia) nograph
kdensity ln_firmage if mg_exp_AO_2002_m==1 & ano==2002, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("(Log) firm age in 2002",size(small)) saving(graphs/rt_fa_2002_fe.gph,replace))      
graph export "graphs/rt_fa_2002_fe.png", as(png) replace
reg ln_firmage mg_exp_AO_2002_m if ano==2002
drop x_ia x_nia y_ia y_nia
// (log) firm age) in 2000
kdensity ln_firmage if mg_exp_AO_2002_m==0 & ano==2000, gen(x_nia y_nia) nograph
kdensity ln_firmage if mg_exp_AO_2002_m==1 & ano==2000, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("(Log) firm age in 2000",size(small)) saving(graphs/rt_fa_2000_fe.gph,replace))      
graph export "graphs/rt_fa_2000_fe.png", as(png) replace
reg ln_firmage mg_exp_AO_2002_m if ano==2000
drop x_ia x_nia y_ia y_nia
// Foreign ownership in 2002
reg foreign mg_exp_AO_2002_m if ano==2002
// Foreign ownership in 2000
reg foreign mg_exp_AO_2002_m if ano==2000




//////////////////////////////////////////////////////////////////////////
//  Step 3B. Figures to compare control and treated firms               //
//           Sample of firm-year that export in t-1 (but not to Angola) //
//////////////////////////////////////////////////////////////////////////

use "`path'/computation/ang.dta",clear
gen od = dest!=8 & dest>=1 & dest<=14 & de_==1
egen nod = sum(od),by(empresa ano)
sort dest empresa ano
gen lnod = nod[_n-1] if empresa==empresa[_n-1] & dest==dest[_n-1]
local ctr_exp_mf = "relsize relapp_lbprod ln_firmage foreign lnod sh_skilled sh_skilled_d relmean_age relsd_age relmean_educ relsd_educ"
marksample regsample
markout `regsample' `ctr_exp_mf' mkt_spec_exp ano  // Deflating variables
keep if `regsample'==1
sort empresa dest ano
keep if (de_[_n-1]==0 & empresa==empresa[_n-1] & dest==dest[_n-1] & other_exporter==0 & lnod>0 & lnod!=.)
keep if dest==8
keep if ano==2000 | ano==2002
gen mg_exp_AO_2002 = 1 if mkt_spec_exp==1 & ano==2002
replace mg_exp_AO_2002 = 0 if mkt_spec_exp==0 & ano==2002
egen mg_exp_AO_2002_m = max(mg_exp_AO_2002),by(empresa)
save rt_sample1,replace
local path = "/Users/lucadavidopromolla/Projects/MOS_rev"
use "`path'/computation/ang.dta",clear
sort empresa dest ano
gen entry = (de_==1 & de_[_n-1]==0 & empresa==empresa[_n-1] & dest==dest[_n-1] & other_exporter==0)
keep if dest==8
keep if ano>=1998 & ano<=2005
collapse (max) entry,by(empresa)
keep if entry==1
keep empresa
sort empresa
merge 1:m empresa using rt_sample1
keep if _merge==3
save rt_sample2,replace
// Specifications without fixed effects
use rt_sample1,clear
// Size in 2002
kdensity relsize if mg_exp_AO_2002_m==0 & ano==2002, gen(x_nia y_nia) nograph
kdensity relsize if mg_exp_AO_2002_m==1 & ano==2002, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm size in 2002",size(small)) saving(graphs/rt_size_2002_expt1.gph,replace))      
graph export "graphs/rt_size_2002_expt1.png", as(png) replace
reg relsize mg_exp_AO_2002_m if ano==2002
drop x_ia x_nia y_ia y_nia
// Size in 2000
kdensity relsize if mg_exp_AO_2002_m==0 & ano==2000, gen(x_nia y_nia) nograph
kdensity relsize if mg_exp_AO_2002_m==1 & ano==2000, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm size in 2000",size(small)) saving(graphs/rt_size_2000_expt1.gph,replace))      
graph export "graphs/rt_size_2000_expt1.png", as(png) replace
reg relsize mg_exp_AO_2002_m if ano==2000
drop x_ia x_nia y_ia y_nia
// Productivity in 2002
kdensity relapp_lbprod if mg_exp_AO_2002_m==0 & ano==2002, gen(x_nia y_nia) nograph
kdensity relapp_lbprod if mg_exp_AO_2002_m==1 & ano==2002, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm productivity in 2002",size(small)) saving(graphs/rt_prod_2002_expt1.gph,replace))      
graph export "graphs/rt_prod_2002_expt1.png", as(png) replace
reg relapp_lbprod mg_exp_AO_2002_m if ano==2002
drop x_ia x_nia y_ia y_nia
// Productivity in 2000
kdensity relapp_lbprod if mg_exp_AO_2002_m==0 & ano==2000, gen(x_nia y_nia) nograph
kdensity relapp_lbprod if mg_exp_AO_2002_m==1 & ano==2000, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm productivity in 2000",size(small)) saving(graphs/rt_prod_2000_expt1.gph,replace))      
graph export "graphs/rt_prod_2000_expt1.png", as(png) replace
reg relapp_lbprod mg_exp_AO_2002_m if ano==2000
drop x_ia x_nia y_ia y_nia
// Number of export destinations in 2002
kdensity lnod if mg_exp_AO_2002_m==0 & ano==2002, gen(x_nia y_nia) nograph
kdensity lnod if mg_exp_AO_2002_m==1 & ano==2002, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm number of export destinations in 2002",size(small)) saving(graphs/rt_lnod_2002_expt1.gph,replace))      
graph export "graphs/rt_lnod_2002_expt1.png", as(png) replace
reg lnod mg_exp_AO_2002_m if ano==2002
drop x_ia x_nia y_ia y_nia
// Number of export destinations in 2000
kdensity lnod if mg_exp_AO_2002_m==0 & ano==2000, gen(x_nia y_nia) nograph
kdensity lnod if mg_exp_AO_2002_m==1 & ano==2000, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm number of export destinations in 2000",size(small)) saving(graphs/rt_lnod_2000_expt1.gph,replace))      
graph export "graphs/rt_lnod_2000_expt1.png", as(png) replace
reg lnod mg_exp_AO_2002_m if ano==2000
drop x_ia x_nia y_ia y_nia
// Share of skilled workers in 2002
kdensity sh_skilled if mg_exp_AO_2002_m==0 & ano==2002, gen(x_nia y_nia) nograph
kdensity sh_skilled if mg_exp_AO_2002_m==1 & ano==2002, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm share of skilled worker in 2002",size(small)) saving(graphs/rt_sh_2002_expt1.gph,replace))      
graph export "graphs/rt_sh_2002_expt1.png", as(png) replace
reg sh_skilled mg_exp_AO_2002_m if ano==2002
drop x_ia x_nia y_ia y_nia
// Share of skilled workers in 2000
kdensity sh_skilled if mg_exp_AO_2002_m==0 & ano==2000, gen(x_nia y_nia) nograph
kdensity sh_skilled if mg_exp_AO_2002_m==1 & ano==2000, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm share of skilled worker in 2000",size(small)) saving(graphs/rt_sh_2000_expt1.gph,replace))      
graph export "graphs/rt_sh_2000_expt1.png", as(png) replace
reg sh_skilled mg_exp_AO_2002_m if ano==2000
drop x_ia x_nia y_ia y_nia
// (log) firm age) in 2002
kdensity ln_firmage if mg_exp_AO_2002_m==0 & ano==2002, gen(x_nia y_nia) nograph
kdensity ln_firmage if mg_exp_AO_2002_m==1 & ano==2002, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("(Log) firm age in 2002",size(small)) saving(graphs/rt_fa_2002_expt1.gph,replace))      
graph export "graphs/rt_fa_2002_expt1.png", as(png) replace
reg ln_firmage mg_exp_AO_2002_m if ano==2002
drop x_ia x_nia y_ia y_nia
// (log) firm age) in 2000
kdensity ln_firmage if mg_exp_AO_2002_m==0 & ano==2000, gen(x_nia y_nia) nograph
kdensity ln_firmage if mg_exp_AO_2002_m==1 & ano==2000, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("(Log) firm age in 2000",size(small)) saving(graphs/rt_fa_2000_expt1.gph,replace))      
graph export "graphs/rt_fa_2000_expt1.png", as(png) replace
reg ln_firmage mg_exp_AO_2002_m if ano==2000
drop x_ia x_nia y_ia y_nia
// Foreign ownership in 2002
reg foreign mg_exp_AO_2002_m if ano==2002
// Foreign ownership in 2000
reg foreign mg_exp_AO_2002_m if ano==2000

// Specifications with fixed effects
// Size in 2002
use rt_sample2,clear
kdensity relsize if mg_exp_AO_2002_m==0 & ano==2002, gen(x_nia y_nia) nograph
kdensity relsize if mg_exp_AO_2002_m==1 & ano==2002, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm size in 2002",size(small)) saving(graphs/rt_size_2002_fe_expt1.gph,replace))      
graph export "graphs/rt_size_2002_fe_expt1.png", as(png) replace
reg relsize mg_exp_AO_2002_m if ano==2002
drop x_ia x_nia y_ia y_nia
// Size in 2000
kdensity relsize if mg_exp_AO_2002_m==0 & ano==2000, gen(x_nia y_nia) nograph
kdensity relsize if mg_exp_AO_2002_m==1 & ano==2000, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm size in 2000",size(small)) saving(graphs/rt_size_2000_fe_expt1.gph,replace))      
graph export "graphs/rt_size_2000_fe_expt1.png", as(png) replace
reg relsize mg_exp_AO_2002_m if ano==2000
drop x_ia x_nia y_ia y_nia
// Productivity in 2002
kdensity relapp_lbprod if mg_exp_AO_2002_m==0 & ano==2002, gen(x_nia y_nia) nograph
kdensity relapp_lbprod if mg_exp_AO_2002_m==1 & ano==2002, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm productivity in 2002",size(small)) saving(graphs/rt_prod_2002_fe_expt1.gph,replace))      
graph export "graphs/rt_prod_2002_fe_expt1.png", as(png) replace
reg relapp_lbprod mg_exp_AO_2002_m if ano==2002
drop x_ia x_nia y_ia y_nia
// Productivity in 2000
kdensity relapp_lbprod if mg_exp_AO_2002_m==0 & ano==2000, gen(x_nia y_nia) nograph
kdensity relapp_lbprod if mg_exp_AO_2002_m==1 & ano==2000, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm productivity in 2000",size(small)) saving(graphs/rt_prod_2000_fe_expt1.gph,replace))      
graph export "graphs/rt_prod_2000_fe_expt1.png", as(png) replace
reg relapp_lbprod mg_exp_AO_2002_m if ano==2000
drop x_ia x_nia y_ia y_nia
// Number of export destinations in 2002
kdensity lnod if mg_exp_AO_2002_m==0 & ano==2002, gen(x_nia y_nia) nograph
kdensity lnod if mg_exp_AO_2002_m==1 & ano==2002, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm number of export destinations in 2002",size(small)) saving(graphs/rt_lnod_2002_fe_expt1.gph,replace))      
graph export "graphs/rt_lnod_2002_fe_expt1.png", as(png) replace
reg lnod mg_exp_AO_2002_m if ano==2002
drop x_ia x_nia y_ia y_nia
// Number of export destinations in 2000
kdensity lnod if mg_exp_AO_2002_m==0 & ano==2000, gen(x_nia y_nia) nograph
kdensity lnod if mg_exp_AO_2002_m==1 & ano==2000, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm number of export destinations in 2000",size(small)) saving(graphs/rt_lnod_2000_fe_expt1.gph,replace))      
graph export "graphs/rt_lnod_2000_fe_expt1.png", as(png) replace
reg lnod mg_exp_AO_2002_m if ano==2000
drop x_ia x_nia y_ia y_nia
// Share of skilled workers in 2002
kdensity sh_skilled if mg_exp_AO_2002_m==0 & ano==2002, gen(x_nia y_nia) nograph
kdensity sh_skilled if mg_exp_AO_2002_m==1 & ano==2002, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm share of skilled worker in 2002",size(small)) saving(graphs/rt_sh_2002_fe_expt1.gph,replace))      
graph export "graphs/rt_sh_2002_fe_expt1.png", as(png) replace
reg sh_skilled mg_exp_AO_2002_m if ano==2002
drop x_ia x_nia y_ia y_nia
// Share of skilled workers in 2000
kdensity sh_skilled if mg_exp_AO_2002_m==0 & ano==2000, gen(x_nia y_nia) nograph
kdensity sh_skilled if mg_exp_AO_2002_m==1 & ano==2000, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("Firm share of skilled worker in 2000",size(small)) saving(graphs/rt_sh_2000_fe_expt1.gph,replace))      
graph export "graphs/rt_sh_2000_fe_expt1.png", as(png) replace
reg sh_skilled mg_exp_AO_2002_m if ano==2000
drop x_ia x_nia y_ia y_nia
// (log) firm age) in 2002
kdensity ln_firmage if mg_exp_AO_2002_m==0 & ano==2002, gen(x_nia y_nia) nograph
kdensity ln_firmage if mg_exp_AO_2002_m==1 & ano==2002, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("(Log) firm age in 2002",size(small)) saving(graphs/rt_fa_2002_fe_expt1.gph,replace))      
graph export "graphs/rt_fa_2002_fe_expt1.png", as(png) replace
reg ln_firmage mg_exp_AO_2002_m if ano==2002
drop x_ia x_nia y_ia y_nia
// (log) firm age) in 2000
kdensity ln_firmage if mg_exp_AO_2002_m==0 & ano==2000, gen(x_nia y_nia) nograph
kdensity ln_firmage if mg_exp_AO_2002_m==1 & ano==2000, gen(x_ia y_ia) nograph
twoway  (line y_nia x_nia,lcolor(gs2) lpattern(solid) sort) || (line y_ia x_ia,lcolor(gs0) lpattern(dash) sort  xlab(#6,labsize(small)) ylab(#6,labsize(small) nogrid) legend(order(1 2) label(1 "No manager with experience to Angola in 2002") label(2 "At least one manager with experience to Angola in 2002")  size(small) region(lcolor(white))) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Density,size(small)) xtitle((Log) Size,size(small)) title("(Log) firm age in 2000",size(small)) saving(graphs/rt_fa_2000_fe_expt1.gph,replace))      
graph export "graphs/rt_fa_2000_fe_expt1.png", as(png) replace
reg ln_firmage mg_exp_AO_2002_m if ano==2000
drop x_ia x_nia y_ia y_nia
// Foreign ownership in 2002
reg foreign mg_exp_AO_2002_m if ano==2002
// Foreign ownership in 2000
reg foreign mg_exp_AO_2002_m if ano==2000



//////////////////////////////////////////////////////////////////////////////////////////////////////
//  Step 4. Table 2 using potential entrants that do export somewhere (not to Angola) in t-1        //
//////////////////////////////////////////////////////////////////////////////////////////////////////



/////////////////////////////////////
//////////// Regressions ////////////
/////////////////////////////////////

cd "`path'/computation"

// Locals
local instruct "tex(pretty frag) tdec(3) rdec(3) auto(3) bdec(3) sdec(3) symbol($^a$,$^b$,$^c$) se label  e(N) nocons"
local ctr_exp_mf = "relsize relapp_lbprod ln_firmage foreign lnod sh_skilled sh_skilled_d relmean_age relsd_age relmean_educ relsd_educ"
local y "y1999 y2000 y2002 y2003 y2004 y2005"
local inta2002 "inta_bf2002"
local inta "inta2002 inta2003 inta2004 inta2005"
local inta_sim "inta20023 inta20045"
local linta_sim "linta20023 linta20045"
local l2inta_sim "l2inta20023 l2inta20045"
local l3inta_sim "l3inta20023 l3inta20045"
local linta "linta2002 linta2003 linta2004 linta2005"
local linta2002 "linta_bf2002"
local linta2002_ang "linta_bf2002_ang"
local y_ang "y1998_ang y1999_ang y2000_ang y2002_ang y2003_ang y2004_ang y2005_ang"
local inta_ang "inta2002_ang inta2003_ang inta2004_ang inta2005_ang"
local linta_ang "linta2002_ang linta2003_ang linta2004_ang linta2005_ang"
local l2inta "l2inta2002 l2inta2003 l2inta2004 l2inta2005"
local l2inta2002 "l2inta_bf2002"
local l2inta2002_ang "l2inta_bf2002_ang"
local l2inta_ang "l2inta2002_ang l2inta2003_ang l2inta2004_ang l2inta2005_ang"
local l3inta "l3inta2002 l3inta2003 l3inta2004 l3inta2005"
local l3inta2002 "l3inta_bf2002"
local l3inta2002_ang "l3inta_bf2002_ang"
local l3inta_ang "l3inta2002_ang l3inta2003_ang l3inta2004_ang l3inta2005_ang"
local winta2002 "winta_bf2002"
local winta "winta2002 winta2003 winta2004 winta2005"
local lwinta "lwinta2002 lwinta2003 lwinta2004 lwinta2005"
local l2winta "l2winta2002 l2winta2003 l2winta2004 l2winta2005"
local l3winta "l3winta2002 l3winta2003 l3winta2004 l3winta2005"
local inta2002_ang "inta_bf2002_ang"


// Load data and merge with common dataset (to use same set of observations in all regressions, by product and by destination)
use MMT_trade_status_entryb_s.dta, clear
merge m:1 empresa ano using common_dataset
keep if _merge==3
drop _merge
cap drop __000000
sort empresa ano
merge m:1 empresa ano using warexp_data
keep if _merge==3
drop _merge
label var warexp "Mg. w/ Conflict Exp. (0/1)"
egen firm_year_tag = tag(empresa ano)
save ang,replace


// Standardize variables (using the common sample standard deviation at the firm-year-level for firm-year variables and at the firm-year-destination-level for specific export experience)
local ctr_exp_mfs = "relsize relapp_lbprod ln_firmage foreign sh_skilled relmean_age relsd_age relmean_educ relsd_educ"
//foreach x of varlist `ctr_exp_mfs' warexp {
foreach x of varlist `ctr_exp_mfs' {
sum `x' if firm_year_tag==1
replace `x' = `x'/r(sd)
}
save MMT_trade_status_entryb_basic,replace
keep if dest==8
egen nobs = count(ano),by(empresa)
tab nobs
keep if nobs==10
keep empresa
sort empresa
save bsample,replace

use MMT_trade_status_entryb_basic,clear

// Prepare Entry Dummy and Other Variables
sort empresa dest ano
gen entry = (de_==1 & de_[_n-1]==0 & empresa==empresa[_n-1] & dest==dest[_n-1] & other_exporter==0) // Keep only period in which the firm can enter into a new destination
egen min_entry = min(ano),by(empresa dest entry)
gen min_entry_t = min_entry if entry==1
egen min_entry2 = min(min_entry_t),by(empresa dest)
gen entry_bs = entry
replace entry_bs = 1 if ano>=min_entry2
drop min_entry min_entry2 min_entry_t
sort empresa dest ano
gen entry2 = (de_[_n+1]==1 & de_==1 & de_[_n-1]==0 & empresa[_n+1]==empresa & empresa==empresa[_n-1] & dest[_n+1]==dest & dest==dest[_n-1] & other_exporter==0) // Keep only period in which the firm can enter into a new destination
sort empresa dest ano
gen lmkt_spec_exp = mkt_spec_exp[_n-1] if dest==dest[_n-1] & empresa==empresa[_n-1]
sort empresa dest ano
gen l2mkt_spec_exp = mkt_spec_exp[_n-2] if dest==dest[_n-2] & empresa==empresa[_n-2]
sort empresa dest ano
gen l3mkt_spec_exp = mkt_spec_exp[_n-3] if dest==dest[_n-3] & empresa==empresa[_n-3]
sort empresa dest ano
gen lwarexp = warexp[_n-1] if dest==dest[_n-1] & empresa==empresa[_n-1]
sort empresa dest ano
gen l2warexp = warexp[_n-2] if dest==dest[_n-2] & empresa==empresa[_n-2]
sort empresa dest ano
gen l3warexp = warexp[_n-3] if dest==dest[_n-3] & empresa==empresa[_n-3]

sort empresa dest ano
forvalues i=1997/2005 {
gen byte y`i' = ano==`i'
gen byte y`i'_ang = (ano==`i')*(dest==8)
gen inta`i' = mkt_spec_exp*(ano==`i')
gen linta`i' = lmkt_spec_exp*(ano==`i')
gen inta`i'_ang = mkt_spec_exp*(ano==`i')*(dest==8)
gen inta`i'_oect = mkt_spec_exp*(ano==`i')*(dest==9 | dest==10 | dest==11 | dest==12 | dest==13 | dest==14)
egen inta`i'_oec = max(inta`i'_oect),by(empresa ano)
gen linta`i'_ang = lmkt_spec_exp*(ano==`i')*(dest==8)
gen l2inta`i' = l2mkt_spec_exp*(ano==`i')
gen l2inta`i'_ang = l2mkt_spec_exp*(ano==`i')*(dest==8)
gen l3inta`i' = l3mkt_spec_exp*(ano==`i')
gen l3inta`i'_ang = l3mkt_spec_exp*(ano==`i')*(dest==8)
gen winta`i' = warexp*(ano==`i')
gen lwinta`i' = lwarexp*(ano==`i')
gen l2winta`i' = l2warexp*(ano==`i')
gen l3winta`i' = l3warexp*(ano==`i')
label var inta`i'_ang "Manag. w/ Angola Exp. * Year=`i' (0/1)"
label var winta`i' "Mg. w/ Conflict Exp. * Year=`i' (0/1)"
}

gen inta_bf2002 = mkt_spec_exp*(ano>=2002)
gen linta_bf2002 = lmkt_spec_exp*(ano>=2002)
gen inta_bf2002_ang = mkt_spec_exp*(ano>=2002)*(dest==8)
gen inta_bf2002_oect = mkt_spec_exp*(ano>=2002)*(dest==9 | dest==10 | dest==11 | dest==12 | dest==13 | dest==14)
egen inta_bf2002_oec = max(inta2002_oect),by(empresa ano)
gen linta_bf2002_ang = lmkt_spec_exp*(ano>=2002)*(dest==8)
gen l2inta_bf2002 = l2mkt_spec_exp*(ano>=2002)
gen l2inta_bf2002_ang = l2mkt_spec_exp*(ano>=2002)*(dest==8)
gen l3inta_bf2002 = l3mkt_spec_exp*(ano>=2002)
gen l3inta_bf2002_ang = l3mkt_spec_exp*(ano>=2002)*(dest==8)
gen winta_bf2002 = warexp*(ano>=2002)
gen lwinta_bf2002 = lwarexp*(ano>=2002)
gen l2winta_bf2002 = l2warexp*(ano>=2002)
gen l3winta_bf2002 = l3warexp*(ano>=2002)
label var inta_bf2002_ang "Manag. w/ Angola Exp. * Year>=2002 (0/1)"
label var winta_bf2002 "Mg. w/ Conflict Exp. * Year>=2002 (0/1)"

gen mkt_spec_exp_ang = mkt_spec_exp*(dest==8)
gen mkt_spec_exp_oect = mkt_spec_exp*(dest==9 | dest==10 | dest==11 | dest==12 | dest==13 | dest==14)
egen mkt_spec_exp_oec = max(mkt_spec_exp_oec),by(empresa ano)
label var mkt_spec_exp_ang "Manag. w/ Angola Exp."
gen ang = dest==8
gen lmkt_spec_exp_ang = lmkt_spec_exp*(dest==8)
gen l2mkt_spec_exp_ang = l2mkt_spec_exp*(dest==8)
gen l3mkt_spec_exp_ang = l3mkt_spec_exp*(dest==8)
gen inta20023 = mkt_spec_exp*(ano>=2002)*(ano<=2003)
gen inta20045 = mkt_spec_exp*(ano>=2004)*(ano<=2005)
gen linta20023 = lmkt_spec_exp*(ano>=2002)*(ano<=2003)
gen linta20045 = lmkt_spec_exp*(ano>=2004)*(ano<=2005)
gen l2inta20023 = l2mkt_spec_exp*(ano>=2002)*(ano<=2003)
gen l2inta20045 = l2mkt_spec_exp*(ano>=2004)*(ano<=2005)
gen l3inta20023 = l3mkt_spec_exp*(ano>=2002)*(ano<=2003)
gen l3inta20045 = l3mkt_spec_exp*(ano>=2004)*(ano<=2005)

forvalues i=1997/2005 {
label var y`i' "Year `i' (0/1)"
label var inta`i' "Year>=`i' * Manag. w/ Spec. Exp. (0/1)"
}
egen empresa_time = group(empresa ano)
gen od = dest!=8 & dest>=1 & dest<=14 & de_==1
egen nod = sum(od),by(empresa ano)
sort dest empresa ano
gen lnod = nod[_n-1] if empresa==empresa[_n-1] & dest==dest[_n-1]
tab dest_time,gen(yrd)

// Keep Firm-Year Pairs with no exports in t-1 + raw regression
sort empresa dest ano
keep if (de_[_n-1]==0 & empresa==empresa[_n-1] & dest==dest[_n-1] & other_exporter==0 & lnod>0 & lnod!=.)
reg entry mkt_spec_exp if dest==8 // Average entry rate in Angola without manager with experience 4.0%, with manager 5.9% (difference significant at 1%)

// Prepare Samples
keep if ano>=1997 & ano<=2005
keep if dest==8
xtset empresa ano
save data_ang_expt1,replace

cd "`path'/results"


// A. Destination experience

// Full-history experience

// A1. Having a manager with export experience to Angola
use "`path'/computation/data_ang_expt1.dta",clear
keep if ano>=1998 & ano<=2005
reg entry mkt_spec_exp `y' `ctr_exp_mf' i.nace,  vce(cluster empresa)
estat summarize
outreg2 using tables/table1dw_ba_expt1.xls, ctitle(OLS) addtext("Firm-time controls", X, "Year FE", X, "Industry FE", X, "Estimation Method", "OLS") `instruct' replace keep(mkt_spec_exp) 
outreg2 using tables/table1dw_ctr_ba_expt1.xls, ctitle(OLS) `instruct' replace keep(`ctr_exp_mf' `y')

use "`path'/computation/data_ang_expt1.dta",clear
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
reg entry_bs mkt_spec_exp `y' `ctr_exp_mf' i.nace,  vce(cluster empresa)
estat summarize
outreg2 using tables/table1dw_bsample_ba_expt1.xls, ctitle(OLS) addtext("Firm-time controls", X, "Year FE", X, "Industry FE", X, "Estimation Method", "OLS") `instruct' replace keep(mkt_spec_exp) 
outreg2 using tables/table1dw_ctr_bsample_ba_expt1.xls, ctitle(OLS) `instruct' replace keep(`ctr_exp_mf' `y')

// A2. Placebo: effect of export experience before the end of the war
use "`path'/computation/data_ang_expt1.dta",clear
keep if ano>=1998 & ano<=2005
reghdfe entry mkt_spec_exp `y' `inta' `ctr_exp_mf', absorb(empresa) vce(cluster empresa) tol(0.001)
outreg2 using tables/table1dw_ba_expt1.xls, ctitle("Placebo") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_ba_expt1.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

use "`path'/computation/data_ang_expt1.dta",clear
keep if ano>=1998 & ano<=2005
reghdfe entry mkt_spec_exp `y' `inta2002' `ctr_exp_mf', absorb(empresa) vce(cluster empresa) tol(0.001)
outreg2 using tables/table1dw_ba_expt1.xls, ctitle("Placebo") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_ba_expt1.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

use "`path'/computation/data_ang_expt1.dta",clear
keep if ano>=1998 & ano<=2005
reg entry mkt_spec_exp `y' `inta' `ctr_exp_mf', vce(cluster empresa)
outreg2 using tables/table1dw_ba_expt1.xls, ctitle("Placebo") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_ba_expt1.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

use "`path'/computation/data_ang_expt1.dta",clear
keep if ano>=1998 & ano<=2005
reg entry mkt_spec_exp `y' `inta2002' `ctr_exp_mf', vce(cluster empresa)
outreg2 using tables/table1dw_ba_expt1.xls, ctitle("Placebo") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_ba_expt1.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize


use "`path'/computation/data_ang_expt1.dta",clear
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
reghdfe entry_bs mkt_spec_exp `y' `inta' `ctr_exp_mf', absorb(empresa) vce(cluster empresa) tol(0.001)
outreg2 using tables/table1dw_bsample_ba_expt1.xls, ctitle("Placebo") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_bsample_ba_expt1.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

use "`path'/computation/data_ang_expt1.dta",clear
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
reghdfe entry_bs mkt_spec_exp `y' `inta2002' `ctr_exp_mf', absorb(empresa) vce(cluster empresa) tol(0.001)
outreg2 using tables/table1dw_bsample_ba_expt1.xls, ctitle("Placebo") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_bsample_ba_expt1.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

use "`path'/computation/data_ang_expt1.dta",clear
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
reg entry_bs mkt_spec_exp `y' `inta' `ctr_exp_mf', vce(cluster empresa)
outreg2 using tables/table1dw_bsample_ba_expt1.xls, ctitle("Placebo") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_bsample_ba_expt1.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

use "`path'/computation/data_ang_expt1.dta",clear
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
reg entry_bs mkt_spec_exp `y' `inta2002' `ctr_exp_mf', vce(cluster empresa)
outreg2 using tables/table1dw_bsample_ba_expt1.xls, ctitle("Placebo") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_bsample_ba_expt1.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize


// A3. Placebo: IV

use "`path'/computation/data_ang_expt1.dta",clear
keep if ano>=1998 & ano<=2005
xtivreg2 entry (mkt_spec_exp `inta' = l3mkt_spec_exp `l3inta' l2mkt_spec_exp `l2inta' lmkt_spec_exp `linta') y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',fe  cluster(empresa) first
outreg2 using tables/table1dw_ba_expt1.xls, ctitle("Placebo IV") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_ba_expt1.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize


use "`path'/computation/data_ang_expt1.dta",clear
keep if ano>=1998 & ano<=2005
su entry mkt_spec_exp `inta2002'  l3mkt_spec_exp `l3inta' l2mkt_spec_exp `l2inta' lmkt_spec_exp `linta' y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf' if ano==2002
xtivreg2 entry (mkt_spec_exp `inta2002' = l3mkt_spec_exp `l3inta2002' l2mkt_spec_exp `l2inta2002' lmkt_spec_exp `linta2002') y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',fe  cluster(empresa) first partial(y1999 y2000 y2002 y2003 y2004 y2005)
outreg2 using tables/table1dw_ba_expt1.xls, ctitle("Placebo IV") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_ba_expt1.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize


use "`path'/computation/data_ang_expt1.dta",clear
keep if ano>=1998 & ano<=2005
ivreg2 entry (mkt_spec_exp `inta' = l3mkt_spec_exp `l3inta' l2mkt_spec_exp `l2inta' lmkt_spec_exp `linta') y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',  cluster(empresa) first
outreg2 using tables/table1dw_ba_expt1.xls, ctitle("Placebo IV") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_ba_expt1.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize


use "`path'/computation/data_ang_expt1.dta",clear
keep if ano>=1998 & ano<=2005
ivreg2 entry (mkt_spec_exp `inta2002' = l3mkt_spec_exp `l3inta2002' l2mkt_spec_exp `l2inta2002' lmkt_spec_exp `linta2002') y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',  cluster(empresa) first
outreg2 using tables/table1dw_ba_expt1.xls, ctitle("Placebo IV") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_ba_expt1.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize



use "`path'/computation/data_ang_expt1.dta",clear
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
//keep if ano<=2003
xtivreg2 entry_bs (mkt_spec_exp `inta' = l3mkt_spec_exp `l3inta' l2mkt_spec_exp `l2inta' lmkt_spec_exp `linta') y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',fe  cluster(empresa) first
outreg2 using tables/table1dw_bsample_ba_expt1.xls, ctitle("Placebo IV") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_bsample_ba_expt1.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize


use "`path'/computation/data_ang_expt1.dta",clear
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
//keep if ano<=2003
xtivreg2 entry_bs (mkt_spec_exp `inta2002' = l3mkt_spec_exp `l3inta2002' l2mkt_spec_exp `l2inta2002' lmkt_spec_exp `linta2002') y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',fe  cluster(empresa) first
outreg2 using tables/table1dw_bsample_ba_expt1.xls, ctitle("Placebo IV") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_bsample_ba_expt1.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

use "`path'/computation/data_ang_expt1.dta",clear
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
ivreg2 entry_bs (mkt_spec_exp `inta' = l3mkt_spec_exp `l3inta' l2mkt_spec_exp `l2inta' lmkt_spec_exp `linta') y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',  cluster(empresa) first
outreg2 using tables/table1dw_bsample_ba_expt1.xls, ctitle("Placebo IV") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_bsample_ba_expt1.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize


use "`path'/computation/data_ang_expt1.dta",clear
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
ivreg2 entry_bs (mkt_spec_exp `inta2002' = l3mkt_spec_exp `l3inta2002' l2mkt_spec_exp `l2inta2002' lmkt_spec_exp `linta2002') y1999 y2000 y2002 y2003 y2004 y2005 `ctr_exp_mf',  cluster(empresa) first
outreg2 using tables/table1dw_bsample_ba_expt1.xls, ctitle("Placebo IV") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_bsample_ba_expt1.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize


//////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Step 5. Using only firm-years with at least two managers, one sales manager and one other manager   //
//////////////////////////////////////////////////////////////////////////////////////////////////////////




cd "`path'/computation"

/////////////////////////////////////
//////////// Prepare data ///////////
/////////////////////////////////////


// 1. Prepare data for firm-destination-year regressions

// Load data and merge with common dataset (to use same set of observations in all regressions, by product and by destination)
use MMT_trade_status_entryb_s.dta, clear
merge m:1 empresa ano using common_dataset
keep if _merge==3
drop _merge
cap drop __000000
sort empresa ano
merge m:1 empresa ano using warexp_data
keep if _merge==3
drop _merge
label var warexp "Mg. w/ Conflict Exp. (0/1)"
egen firm_year_tag = tag(empresa ano)
save ang_sal,replace


// Standardize variables (using the common sample standard deviation at the firm-year-level for firm-year variables and at the firm-year-destination-level for specific export experience)
local ctr_exp_mfs = "relsize relapp_lbprod ln_firmage foreign sh_skilled relmean_age relsd_age relmean_educ relsd_educ"
foreach x of varlist `ctr_exp_mfs' {
sum `x' if firm_year_tag==1
replace `x' = `x'/r(sd)
}
save MMT_trade_status_entryb_basic_sal,replace

// Balanced sample 
keep if dest==8
egen nobs = count(ano),by(empresa)
tab nobs
keep if nobs==10
keep empresa
sort empresa
save bsample_sal,replace

// Prepare Entry Dummy and Other Variables
use MMT_trade_status_entryb_basic_sal,clear
sort empresa dest ano
gen entry = (de_==1 & de_[_n-1]==0 & empresa==empresa[_n-1] & dest==dest[_n-1] & other_exporter==0) // Keep only period in which the firm can enter into a new destination
egen min_entry = min(ano),by(empresa dest entry)
gen min_entry_t = min_entry if entry==1
egen min_entry2 = min(min_entry_t),by(empresa dest)
gen entry_bs = entry
replace entry_bs = 1 if ano>=min_entry2
drop min_entry min_entry2 min_entry_t
sort empresa dest ano
gen lmkt_spec_exp = mkt_spec_exp[_n-1] if dest==dest[_n-1] & empresa==empresa[_n-1]
sort empresa dest ano
gen l2mkt_spec_exp = mkt_spec_exp[_n-2] if dest==dest[_n-2] & empresa==empresa[_n-2]
sort empresa dest ano
gen l3mkt_spec_exp = mkt_spec_exp[_n-3] if dest==dest[_n-3] & empresa==empresa[_n-3]
sort empresa dest ano
gen lmkt_spec_exp2 = mkt_spec_exp2[_n-1] if dest==dest[_n-1] & empresa==empresa[_n-1]
sort empresa dest ano
gen l2mkt_spec_exp2 = mkt_spec_exp2[_n-2] if dest==dest[_n-2] & empresa==empresa[_n-2]
sort empresa dest ano
gen l3mkt_spec_exp2 = mkt_spec_exp2[_n-3] if dest==dest[_n-3] & empresa==empresa[_n-3]
sort empresa dest ano
gen lwarexp = warexp[_n-1] if dest==dest[_n-1] & empresa==empresa[_n-1]
sort empresa dest ano
gen l2warexp = warexp[_n-2] if dest==dest[_n-2] & empresa==empresa[_n-2]
sort empresa dest ano
gen l3warexp = warexp[_n-3] if dest==dest[_n-3] & empresa==empresa[_n-3]
sort empresa dest ano

sort empresa dest ano
forvalues i=1997/2005 {
gen byte y`i' = ano==`i'
gen byte y`i'_ang = (ano==`i')*(dest==8)
gen inta`i' = mkt_spec_exp*(ano==`i')
gen linta`i' = lmkt_spec_exp*(ano==`i')
gen inta`i'_ang = mkt_spec_exp*(ano==`i')*(dest==8)
gen inta`i'_oect = mkt_spec_exp*(ano==`i')*(dest==9 | dest==10 | dest==11 | dest==12 | dest==13 | dest==14)
egen inta`i'_oec = max(inta`i'_oect),by(empresa ano)
gen linta`i'_ang = lmkt_spec_exp*(ano==`i')*(dest==8)
gen l2inta`i' = l2mkt_spec_exp*(ano==`i')
gen l2inta`i'_ang = l2mkt_spec_exp*(ano==`i')*(dest==8)
gen l3inta`i' = l3mkt_spec_exp*(ano==`i')
gen l3inta`i'_ang = l3mkt_spec_exp*(ano==`i')*(dest==8)

gen inta2`i' = mkt_spec_exp2*(ano==`i')
gen linta2`i' = lmkt_spec_exp2*(ano==`i')
gen inta2`i'_ang = mkt_spec_exp2*(ano==`i')*(dest==8)
gen inta2`i'_oect = mkt_spec_exp2*(ano==`i')*(dest==9 | dest==10 | dest==11 | dest==12 | dest==13 | dest==14)
egen inta2`i'_oec = max(inta2`i'_oect),by(empresa ano)
gen linta2`i'_ang = lmkt_spec_exp2*(ano==`i')*(dest==8)
gen l2inta2`i' = l2mkt_spec_exp2*(ano==`i')
gen l2inta2`i'_ang = l2mkt_spec_exp2*(ano==`i')*(dest==8)
gen l3inta2`i' = l3mkt_spec_exp2*(ano==`i')
gen l3inta2`i'_ang = l3mkt_spec_exp2*(ano==`i')*(dest==8)


gen winta`i' = warexp*(ano==`i')
gen lwinta`i' = lwarexp*(ano==`i')
gen l2winta`i' = l2warexp*(ano==`i')
gen l3winta`i' = l3warexp*(ano==`i')
label var inta`i'_ang "Manag. w/ Angola Exp. * Year==`i' (0/1)"
label var inta2`i'_ang "Sales Manag. w/ Angola Exp. * Year==`i' (0/1)"
label var winta`i' "Mg. w/ Conflict Exp. * Year==`i' (0/1)"
}

gen inta_bf2002 = mkt_spec_exp*(ano>=2002)
gen linta_bf2002 = lmkt_spec_exp*(ano>=2002)
gen inta_bf2002_ang = mkt_spec_exp*(ano>=2002)*(dest==8)
gen inta_bf2002_oect = mkt_spec_exp*(ano>=2002)*(dest==9 | dest==10 | dest==11 | dest==12 | dest==13 | dest==14)
egen inta_bf2002_oec = max(inta2002_oect),by(empresa ano)
gen linta_bf2002_ang = lmkt_spec_exp*(ano>=2002)*(dest==8)
gen l2inta_bf2002 = l2mkt_spec_exp*(ano>=2002)
gen l2inta_bf2002_ang = l2mkt_spec_exp*(ano>=2002)*(dest==8)
gen l3inta_bf2002 = l3mkt_spec_exp*(ano>=2002)
gen l3inta_bf2002_ang = l3mkt_spec_exp*(ano>=2002)*(dest==8)
gen winta_bf2002 = warexp*(ano>=2002)
gen lwinta_bf2002 = lwarexp*(ano>=2002)
gen l2winta_bf2002 = l2warexp*(ano>=2002)
gen l3winta_bf2002 = l3warexp*(ano>=2002)
label var inta_bf2002_ang "Manag. w/ Angola Exp. * Year>=2002 (0/1)"
label var winta_bf2002 "Mg. w/ Conflict Exp. * Year>=2002 (0/1)"

gen inta_bf22002 = mkt_spec_exp2*(ano>=2002)
gen linta_bf22002 = lmkt_spec_exp2*(ano>=2002)
gen inta_bf22002_ang = mkt_spec_exp2*(ano>=2002)*(dest==8)
gen inta_bf22002_oect = mkt_spec_exp2*(ano>=2002)*(dest==9 | dest==10 | dest==11 | dest==12 | dest==13 | dest==14)
egen inta_bf22002_oec = max(inta22002_oect),by(empresa ano)
gen linta_bf22002_ang = lmkt_spec_exp2*(ano>=2002)*(dest==8)
gen l2inta_bf22002 = l2mkt_spec_exp2*(ano>=2002)
gen l2inta_bf22002_ang = l2mkt_spec_exp2*(ano>=2002)*(dest==8)
gen l3inta_bf22002 = l3mkt_spec_exp2*(ano>=2002)
gen l3inta_bf22002_ang = l3mkt_spec_exp2*(ano>=2002)*(dest==8)
//gen winta2_bf2002 = warexp2*(ano>=2002)
//gen lwinta2_bf2002 = lwarexp2*(ano>=2002)
//gen l2winta2_bf2002 = l2warexp2*(ano>=2002)
//gen l3winta2_bf2002 = l3warexp2*(ano>=2002)
label var inta_bf22002_ang "Sales Manag. w/ Angola Exp. * Year>=2002 (0/1)"
//label var winta2_bf2002 "Sales Mg. w/ Conflict Exp. * Year>=2002 (0/1)"


gen mkt_spec_exp_ang = mkt_spec_exp*(dest==8)
gen mkt_spec_exp_oect = mkt_spec_exp*(dest==9 | dest==10 | dest==11 | dest==12 | dest==13 | dest==14)
egen mkt_spec_exp_oec = max(mkt_spec_exp_oec),by(empresa ano)
label var mkt_spec_exp_ang "Manag. w/ Angola Exp."

gen mkt_spec_exp2_ang = mkt_spec_exp2*(dest==8)
gen mkt_spec_exp2_oect = mkt_spec_exp2*(dest==9 | dest==10 | dest==11 | dest==12 | dest==13 | dest==14)
egen mkt_spec_exp2_oec = max(mkt_spec_exp2_oec),by(empresa ano)
label var mkt_spec_exp2_ang "Manag. w/ Angola Exp."


gen ang = dest==8
gen lmkt_spec_exp_ang = lmkt_spec_exp*(dest==8)
gen l2mkt_spec_exp_ang = l2mkt_spec_exp*(dest==8)
gen l3mkt_spec_exp_ang = l3mkt_spec_exp*(dest==8)
gen inta20023 = mkt_spec_exp*(ano>=2002)*(ano<=2003)
gen inta20045 = mkt_spec_exp*(ano>=2004)*(ano<=2005)
gen linta20023 = lmkt_spec_exp*(ano>=2002)*(ano<=2003)
gen linta20045 = lmkt_spec_exp*(ano>=2004)*(ano<=2005)
gen l2inta20023 = l2mkt_spec_exp*(ano>=2002)*(ano<=2003)
gen l2inta20045 = l2mkt_spec_exp*(ano>=2004)*(ano<=2005)
gen l3inta20023 = l3mkt_spec_exp*(ano>=2002)*(ano<=2003)
gen l3inta20045 = l3mkt_spec_exp*(ano>=2004)*(ano<=2005)

gen lmkt_spec_exp2_ang = lmkt_spec_exp2*(dest==8)
gen l2mkt_spec_exp2_ang = l2mkt_spec_exp2*(dest==8)
gen l3mkt_spec_exp2_ang = l3mkt_spec_exp2*(dest==8)
gen inta220023 = mkt_spec_exp2*(ano>=2002)*(ano<=2003)
gen inta220045 = mkt_spec_exp2*(ano>=2004)*(ano<=2005)
gen linta220023 = lmkt_spec_exp2*(ano>=2002)*(ano<=2003)
gen linta220045 = lmkt_spec_exp2*(ano>=2004)*(ano<=2005)
gen l2inta220023 = l2mkt_spec_exp2*(ano>=2002)*(ano<=2003)
gen l2inta220045 = l2mkt_spec_exp2*(ano>=2004)*(ano<=2005)
gen l3inta220023 = l3mkt_spec_exp2*(ano>=2002)*(ano<=2003)
gen l3inta220045 = l3mkt_spec_exp2*(ano>=2004)*(ano<=2005)


forvalues i=1997/2005 {
label var y`i' "Year `i' (0/1)"
label var inta`i' "Year==`i' * Manag. w/ Spec. Exp. (0/1)"
label var inta2`i' "Year==`i' * Sales Manag. w/ Spec. Exp. (0/1)"
}
egen empresa_time = group(empresa ano)
gen od = dest!=8 & dest>=1 & dest<=14 & de_==1
egen nod = sum(od),by(empresa ano)
sort dest empresa ano
gen lnod = nod[_n-1] if empresa==empresa[_n-1] & dest==dest[_n-1]
tab dest_time,gen(yrd)

// Keep Firm-Year Pairs with no exports in t-1 + raw regression
sort empresa dest ano
keep if (de_[_n-1]==0 & empresa==empresa[_n-1] & dest==dest[_n-1] & other_exporter==0)
reg entry mkt_spec_exp if dest==8 // Average entry rate in Angola without manager with experience 4.0%, with manager 5.9% (difference significant at 1%)

// Prepare Samples
//use MMT_trade_status_entryb_s1.dta, clear
keep if ano>=1997 & ano<=2005
keep if dest==8 | dest==9 | dest==10 | dest==11 | dest==12 | dest==13 | dest==14
xtset empresa_time dest
save data_excol_sal,replace
keep if dest==8
xtset empresa ano
save data_ang_sal,replace
keep empresa ano
save dataset_ang_sal,replace


// Locals
local instruct "tex(pretty frag) tdec(3) rdec(3) auto(3) bdec(3) sdec(3) symbol($^a$,$^b$,$^c$) se label  e(N) nocons"
local ctr_exp_mf = "relsize relapp_lbprod ln_firmage foreign lnod sh_skilled sh_skilled_d relmean_age relsd_age relmean_educ relsd_educ"
local y "y1999 y2000 y2002 y2003 y2004 y2005"
local inta2002 "inta_bf2002"
local inta "inta2002 inta2003 inta2004 inta2005"
local inta_sim "inta20023 inta20045"
local linta_sim "linta20023 linta20045"
local l2inta_sim "l2inta20023 l2inta20045"
local l3inta_sim "l3inta20023 l3inta20045"
local linta "linta2002 linta2003 linta2004 linta2005"
local linta2002 "linta_bf2002"
local linta2002_ang "linta_bf2002_ang"

local inta22002 "inta_bf22002"
local inta2 "inta22002 inta22003 inta22004 inta22005"
local inta2_sim "inta220023 inta220045"
local linta2_sim "linta220023 linta220045"
local l2inta2_sim "l2inta220023 l2inta220045"
local l3inta2_sim "l3inta220023 l3inta220045"
local linta2 "linta22002 linta22003 linta22004 linta22005"
local linta22002 "linta_bf22002"
local linta22002_ang "linta_bf22002_ang"

local y_ang "y1998_ang y1999_ang y2000_ang y2002_ang y2003_ang y2004_ang y2005_ang"
local inta_ang "inta2002_ang inta2003_ang inta2004_ang inta2005_ang"
local linta_ang "linta2002_ang linta2003_ang linta2004_ang linta2005_ang"
local l2inta "l2inta2002 l2inta2003 l2inta2004 l2inta2005"
local l2inta2002 "l2inta_bf2002"
local l2inta2002_ang "l2inta_bf2002_ang"
local l2inta_ang "l2inta2002_ang l2inta2003_ang l2inta2004_ang l2inta2005_ang"
local l3inta "l3inta2002 l3inta2003 l3inta2004 l3inta2005"
local l3inta2002 "l3inta_bf2002"
local l3inta2002_ang "l3inta_bf2002_ang"
local l3inta_ang "l3inta2002_ang l3inta2003_ang l3inta2004_ang l3inta2005_ang"

local inta2_ang "inta22002_ang inta22003_ang inta22004_ang inta22005_ang"
local linta2_ang "linta22002_ang linta22003_ang linta22004_ang linta22005_ang"
local l2inta2 "l2inta22002 l2inta22003 l2inta22004 l2inta22005"
local l2inta22002 "l2inta_bf22002"
local l2inta22002_ang "l2inta_bf22002_ang"
local l2inta2_ang "l2inta22002_ang l2inta22003_ang l2inta22004_ang l2inta22005_ang"
local l3inta2 "l3inta22002 l3inta22003 l3inta22004 l3inta22005"
local l3inta22002 "l3inta_bf22002"
local l3inta22002_ang "l3inta_bf22002_ang"
local l3inta2_ang "l3inta22002_ang l3inta22003_ang l3inta22004_ang l3inta22005_ang"


local winta2002 "winta_bf2002"
local winta "winta2002 winta2003 winta2004 winta2005"
local lwinta "lwinta2002 lwinta2003 lwinta2004 lwinta2005"
local l2winta "l2winta2002 l2winta2003 l2winta2004 l2winta2005"
local l3winta "l3winta2002 l3winta2003 l3winta2004 l3winta2005"
local inta2002_ang "inta_bf2002_ang"
local inta22002_ang "inta_bf22002_ang"

cd "`path'/results"


// A. Destination experience

// Full-history experience

// A1. Having a manager with export experience to Angola
use "`path'/computation/data_ang_sal.dta",clear
keep if mant1==1 & mant2==1
keep if ano>=1998 & ano<=2005
reg entry mkt_spec_exp mkt_spec_exp2 `y' `ctr_exp_mf' i.nace,  vce(cluster empresa)
estat summarize
outreg2 using tables/table1dw_ba_sal.xls, ctitle(OLS) addtext("Firm-time controls", X, "Year FE", X, "Industry FE", X, "Estimation Method", "OLS") `instruct' replace keep(mkt_spec_exp mkt_spec_exp2) 
outreg2 using tables/table1dw_ctr_ba_sal.xls, ctitle(OLS) `instruct' replace keep(`ctr_exp_mf' `y')

use "`path'/computation/data_ang_sal.dta",clear
keep if mant1==1 & mant2==1
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample_sal.dta"
keep if _merge==3
drop _merge
reg entry_bs mkt_spec_exp mkt_spec_exp2 `y' `ctr_exp_mf' i.nace,  vce(cluster empresa)
estat summarize
outreg2 using tables/table1dw_bsample_ba_sal.xls, ctitle(OLS) addtext("Firm-time controls", X, "Year FE", X, "Industry FE", X, "Estimation Method", "OLS") `instruct' replace keep(mkt_spec_exp mkt_spec_exp2) 
outreg2 using tables/table1dw_ctr_bsample_ba_sal.xls, ctitle(OLS) `instruct' replace keep(`ctr_exp_mf' `y')

// A2. Placebo: effect of export experience before the end of the war
use "`path'/computation/data_ang_sal.dta",clear
keep if mant1==1 & mant2==1
keep if ano>=1998 & ano<=2005
reghdfe entry mkt_spec_exp mkt_spec_exp2 `y' `inta' `inta2' `ctr_exp_mf', absorb(empresa) vce(cluster empresa) tol(0.001)
outreg2 using tables/table1dw_ba_sal.xls, ctitle("Placebo") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp mkt_spec_exp2 `inta' `inta2') 
outreg2 using tables/table1dw_ctr_ba_sal.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

use "`path'/computation/data_ang_sal.dta",clear
keep if mant1==1 & mant2==1
keep if ano>=1998 & ano<=2005
reghdfe entry mkt_spec_exp mkt_spec_exp2 `y' `inta2002' `inta22002' `ctr_exp_mf', absorb(empresa) vce(cluster empresa) tol(0.001)
outreg2 using tables/table1dw_ba_sal.xls, ctitle("Placebo") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp mkt_spec_exp2 `inta2002' `inta22002') 
outreg2 using tables/table1dw_ctr_ba_sal.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

use "`path'/computation/data_ang_sal.dta",clear
keep if mant1==1 & mant2==1
keep if ano>=1998 & ano<=2005
reg entry mkt_spec_exp mkt_spec_exp2 `y' `inta' `inta2' `ctr_exp_mf', vce(cluster empresa)
outreg2 using tables/table1dw_ba_sal.xls, ctitle("Placebo") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta' `inta2') 
outreg2 using tables/table1dw_ctr_ba_sal.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

use "`path'/computation/data_ang_sal.dta",clear
keep if mant1==1 & mant2==1
keep if ano>=1998 & ano<=2005
reg entry mkt_spec_exp mkt_spec_exp2 `y' `inta2002' `inta22002' `ctr_exp_mf', vce(cluster empresa)
outreg2 using tables/table1dw_ba_sal.xls, ctitle("Placebo") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta2002' `inta22002') 
outreg2 using tables/table1dw_ctr_ba_sal.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

use "`path'/computation/data_ang_sal.dta",clear
keep if mant1==1 & mant2==1
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample_sal.dta"
keep if _merge==3
drop _merge
reghdfe entry_bs mkt_spec_exp mkt_spec_exp2 `y' `inta' `inta2' `ctr_exp_mf', absorb(empresa) vce(cluster empresa) tol(0.001)
outreg2 using tables/table1dw_bsample_ba_sal.xls, ctitle("Placebo") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta' `inta2') 
outreg2 using tables/table1dw_ctr_bsample_ba_sal.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

use "`path'/computation/data_ang_sal.dta",clear
keep if mant1==1 & mant2==1
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample_sal.dta"
keep if _merge==3
drop _merge
reghdfe entry_bs mkt_spec_exp mkt_spec_exp2 `y' `inta2002' `inta22002' `ctr_exp_mf', absorb(empresa) vce(cluster empresa) tol(0.001)
outreg2 using tables/table1dw_bsample_ba_sal.xls, ctitle("Placebo") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta2002' `inta22002') 
outreg2 using tables/table1dw_ctr_bsample_ba_sal.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

use "`path'/computation/data_ang_sal.dta",clear
keep if mant1==1 & mant2==1
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample_sal.dta"
keep if _merge==3
drop _merge
reg entry_bs mkt_spec_exp mkt_spec_exp2 `y' `inta' `inta2' `ctr_exp_mf', vce(cluster empresa)
outreg2 using tables/table1dw_bsample_ba_sal.xls, ctitle("Placebo") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta' `inta2') 
outreg2 using tables/table1dw_ctr_bsample_ba_sal.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

use "`path'/computation/data_ang_sal.dta",clear
keep if mant1==1 & mant2==1
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample_sal.dta"
keep if _merge==3
drop _merge
reg entry_bs mkt_spec_exp mkt_spec_exp2 `y' `inta2002' `inta22002' `ctr_exp_mf', vce(cluster empresa)
outreg2 using tables/table1dw_bsample_ba_sal.xls, ctitle("Placebo") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta2002' `inta22002') 
outreg2 using tables/table1dw_ctr_bsample_ba_sal.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize



/////////////////////////////////////////////////////////////////////////////////////////////
//  Step 6. Using current sample but distinguishing between managers and sales managers    //
/////////////////////////////////////////////////////////////////////////////////////////////



cd "`path'/computation"

/////////////////////////////////////
//////////// Prepare data ///////////
/////////////////////////////////////


// 1. Prepare data for firm-destination-year regressions

// Load data and merge with common dataset (to use same set of observations in all regressions, by product and by destination)
use MMT_trade_status_entryb_s.dta, clear
merge m:1 empresa ano using common_dataset
keep if _merge==3
drop _merge
cap drop __000000
sort empresa ano
merge m:1 empresa ano using warexp_data
keep if _merge==3
drop _merge
label var warexp "Mg. w/ Conflict Exp. (0/1)"
egen firm_year_tag = tag(empresa ano)
save ang_sal2,replace


// Standardize variables (using the common sample standard deviation at the firm-year-level for firm-year variables and at the firm-year-destination-level for specific export experience)
local ctr_exp_mfs = "relsize relapp_lbprod ln_firmage foreign sh_skilled relmean_age relsd_age relmean_educ relsd_educ"
foreach x of varlist `ctr_exp_mfs' {
sum `x' if firm_year_tag==1
replace `x' = `x'/r(sd)
}
save MMT_trade_status_entryb_basic_sal2,replace

// Balanced sample 
keep if dest==8
egen nobs = count(ano),by(empresa)
tab nobs
keep if nobs==10
keep empresa
sort empresa
save bsample_sal2,replace

// Prepare Entry Dummy and Other Variables
use MMT_trade_status_entryb_basic_sal2,clear
sort empresa dest ano
gen entry = (de_==1 & de_[_n-1]==0 & empresa==empresa[_n-1] & dest==dest[_n-1] & other_exporter==0) // Keep only period in which the firm can enter into a new destination
egen min_entry = min(ano),by(empresa dest entry)
gen min_entry_t = min_entry if entry==1
egen min_entry2 = min(min_entry_t),by(empresa dest)
gen entry_bs = entry
replace entry_bs = 1 if ano>=min_entry2
drop min_entry min_entry2 min_entry_t
sort empresa dest ano
gen lmkt_spec_exp = mkt_spec_exp[_n-1] if dest==dest[_n-1] & empresa==empresa[_n-1]
sort empresa dest ano
gen l2mkt_spec_exp = mkt_spec_exp[_n-2] if dest==dest[_n-2] & empresa==empresa[_n-2]
sort empresa dest ano
gen l3mkt_spec_exp = mkt_spec_exp[_n-3] if dest==dest[_n-3] & empresa==empresa[_n-3]
sort empresa dest ano
gen lmkt_spec_exp2 = mkt_spec_exp2[_n-1] if dest==dest[_n-1] & empresa==empresa[_n-1]
sort empresa dest ano
gen l2mkt_spec_exp2 = mkt_spec_exp2[_n-2] if dest==dest[_n-2] & empresa==empresa[_n-2]
sort empresa dest ano
gen l3mkt_spec_exp2 = mkt_spec_exp2[_n-3] if dest==dest[_n-3] & empresa==empresa[_n-3]
sort empresa dest ano
gen lwarexp = warexp[_n-1] if dest==dest[_n-1] & empresa==empresa[_n-1]
sort empresa dest ano
gen l2warexp = warexp[_n-2] if dest==dest[_n-2] & empresa==empresa[_n-2]
sort empresa dest ano
gen l3warexp = warexp[_n-3] if dest==dest[_n-3] & empresa==empresa[_n-3]
sort empresa dest ano

sort empresa dest ano
forvalues i=1997/2005 {
gen byte y`i' = ano==`i'
gen byte y`i'_ang = (ano==`i')*(dest==8)
gen inta`i' = mkt_spec_exp*(ano==`i')
gen linta`i' = lmkt_spec_exp*(ano==`i')
gen inta`i'_ang = mkt_spec_exp*(ano==`i')*(dest==8)
gen inta`i'_oect = mkt_spec_exp*(ano==`i')*(dest==9 | dest==10 | dest==11 | dest==12 | dest==13 | dest==14)
egen inta`i'_oec = max(inta`i'_oect),by(empresa ano)
gen linta`i'_ang = lmkt_spec_exp*(ano==`i')*(dest==8)
gen l2inta`i' = l2mkt_spec_exp*(ano==`i')
gen l2inta`i'_ang = l2mkt_spec_exp*(ano==`i')*(dest==8)
gen l3inta`i' = l3mkt_spec_exp*(ano==`i')
gen l3inta`i'_ang = l3mkt_spec_exp*(ano==`i')*(dest==8)

gen inta2`i' = mkt_spec_exp2*(ano==`i')
gen linta2`i' = lmkt_spec_exp2*(ano==`i')
gen inta2`i'_ang = mkt_spec_exp2*(ano==`i')*(dest==8)
gen inta2`i'_oect = mkt_spec_exp2*(ano==`i')*(dest==9 | dest==10 | dest==11 | dest==12 | dest==13 | dest==14)
egen inta2`i'_oec = max(inta2`i'_oect),by(empresa ano)
gen linta2`i'_ang = lmkt_spec_exp2*(ano==`i')*(dest==8)
gen l2inta2`i' = l2mkt_spec_exp2*(ano==`i')
gen l2inta2`i'_ang = l2mkt_spec_exp2*(ano==`i')*(dest==8)
gen l3inta2`i' = l3mkt_spec_exp2*(ano==`i')
gen l3inta2`i'_ang = l3mkt_spec_exp2*(ano==`i')*(dest==8)


gen winta`i' = warexp*(ano==`i')
gen lwinta`i' = lwarexp*(ano==`i')
gen l2winta`i' = l2warexp*(ano==`i')
gen l3winta`i' = l3warexp*(ano==`i')
label var inta`i'_ang "Manag. w/ Angola Exp. * Year==`i' (0/1)"
label var inta2`i'_ang "Sales Manag. w/ Angola Exp. * Year==`i' (0/1)"
label var winta`i' "Mg. w/ Conflict Exp. * Year==`i' (0/1)"
}

gen inta_bf2002 = mkt_spec_exp*(ano>=2002)
gen linta_bf2002 = lmkt_spec_exp*(ano>=2002)
gen inta_bf2002_ang = mkt_spec_exp*(ano>=2002)*(dest==8)
gen inta_bf2002_oect = mkt_spec_exp*(ano>=2002)*(dest==9 | dest==10 | dest==11 | dest==12 | dest==13 | dest==14)
egen inta_bf2002_oec = max(inta2002_oect),by(empresa ano)
gen linta_bf2002_ang = lmkt_spec_exp*(ano>=2002)*(dest==8)
gen l2inta_bf2002 = l2mkt_spec_exp*(ano>=2002)
gen l2inta_bf2002_ang = l2mkt_spec_exp*(ano>=2002)*(dest==8)
gen l3inta_bf2002 = l3mkt_spec_exp*(ano>=2002)
gen l3inta_bf2002_ang = l3mkt_spec_exp*(ano>=2002)*(dest==8)
gen winta_bf2002 = warexp*(ano>=2002)
gen lwinta_bf2002 = lwarexp*(ano>=2002)
gen l2winta_bf2002 = l2warexp*(ano>=2002)
gen l3winta_bf2002 = l3warexp*(ano>=2002)
label var inta_bf2002_ang "Manag. w/ Angola Exp. * Year>=2002 (0/1)"
label var winta_bf2002 "Mg. w/ Conflict Exp. * Year>=2002 (0/1)"


gen inta_bf22002 = mkt_spec_exp2*(ano>=2002)
gen linta_bf22002 = lmkt_spec_exp2*(ano>=2002)
gen inta_bf22002_ang = mkt_spec_exp2*(ano>=2002)*(dest==8)
gen inta_bf22002_oect = mkt_spec_exp2*(ano>=2002)*(dest==9 | dest==10 | dest==11 | dest==12 | dest==13 | dest==14)
egen inta_bf22002_oec = max(inta22002_oect),by(empresa ano)
gen linta_bf22002_ang = lmkt_spec_exp2*(ano>=2002)*(dest==8)
gen l2inta_bf22002 = l2mkt_spec_exp2*(ano>=2002)
gen l2inta_bf22002_ang = l2mkt_spec_exp2*(ano>=2002)*(dest==8)
gen l3inta_bf22002 = l3mkt_spec_exp2*(ano>=2002)
gen l3inta_bf22002_ang = l3mkt_spec_exp2*(ano>=2002)*(dest==8)
//gen winta2_bf2002 = warexp2*(ano>=2002)
//gen lwinta2_bf2002 = lwarexp2*(ano>=2002)
//gen l2winta2_bf2002 = l2warexp2*(ano>=2002)
//gen l3winta2_bf2002 = l3warexp2*(ano>=2002)
label var inta_bf22002_ang "Sales Manag. w/ Angola Exp. * Year>=2002 (0/1)"
//label var winta2_bf2002 "Sales Mg. w/ Conflict Exp. * Year>=2002 (0/1)"


gen mkt_spec_exp_ang = mkt_spec_exp*(dest==8)
gen mkt_spec_exp_oect = mkt_spec_exp*(dest==9 | dest==10 | dest==11 | dest==12 | dest==13 | dest==14)
egen mkt_spec_exp_oec = max(mkt_spec_exp_oec),by(empresa ano)
label var mkt_spec_exp_ang "Manag. w/ Angola Exp."

gen mkt_spec_exp2_ang = mkt_spec_exp2*(dest==8)
gen mkt_spec_exp2_oect = mkt_spec_exp2*(dest==9 | dest==10 | dest==11 | dest==12 | dest==13 | dest==14)
egen mkt_spec_exp2_oec = max(mkt_spec_exp2_oec),by(empresa ano)
label var mkt_spec_exp2_ang "Manag. w/ Angola Exp."


gen ang = dest==8
gen lmkt_spec_exp_ang = lmkt_spec_exp*(dest==8)
gen l2mkt_spec_exp_ang = l2mkt_spec_exp*(dest==8)
gen l3mkt_spec_exp_ang = l3mkt_spec_exp*(dest==8)
gen inta20023 = mkt_spec_exp*(ano>=2002)*(ano<=2003)
gen inta20045 = mkt_spec_exp*(ano>=2004)*(ano<=2005)
gen linta20023 = lmkt_spec_exp*(ano>=2002)*(ano<=2003)
gen linta20045 = lmkt_spec_exp*(ano>=2004)*(ano<=2005)
gen l2inta20023 = l2mkt_spec_exp*(ano>=2002)*(ano<=2003)
gen l2inta20045 = l2mkt_spec_exp*(ano>=2004)*(ano<=2005)
gen l3inta20023 = l3mkt_spec_exp*(ano>=2002)*(ano<=2003)
gen l3inta20045 = l3mkt_spec_exp*(ano>=2004)*(ano<=2005)

gen lmkt_spec_exp2_ang = lmkt_spec_exp2*(dest==8)
gen l2mkt_spec_exp2_ang = l2mkt_spec_exp2*(dest==8)
gen l3mkt_spec_exp2_ang = l3mkt_spec_exp2*(dest==8)
gen inta220023 = mkt_spec_exp2*(ano>=2002)*(ano<=2003)
gen inta220045 = mkt_spec_exp2*(ano>=2004)*(ano<=2005)
gen linta220023 = lmkt_spec_exp2*(ano>=2002)*(ano<=2003)
gen linta220045 = lmkt_spec_exp2*(ano>=2004)*(ano<=2005)
gen l2inta220023 = l2mkt_spec_exp2*(ano>=2002)*(ano<=2003)
gen l2inta220045 = l2mkt_spec_exp2*(ano>=2004)*(ano<=2005)
gen l3inta220023 = l3mkt_spec_exp2*(ano>=2002)*(ano<=2003)
gen l3inta220045 = l3mkt_spec_exp2*(ano>=2004)*(ano<=2005)


forvalues i=1997/2005 {
label var y`i' "Year `i' (0/1)"
label var inta`i' "Year==`i' * Manag. w/ Spec. Exp. (0/1)"
label var inta2`i' "Year==`i' * Sales Manag. w/ Spec. Exp. (0/1)"
}
egen empresa_time = group(empresa ano)
gen od = dest!=8 & dest>=1 & dest<=14 & de_==1
egen nod = sum(od),by(empresa ano)
sort dest empresa ano
gen lnod = nod[_n-1] if empresa==empresa[_n-1] & dest==dest[_n-1]
tab dest_time,gen(yrd)

// Keep Firm-Year Pairs with no exports in t-1 + raw regression
sort empresa dest ano
keep if (de_[_n-1]==0 & empresa==empresa[_n-1] & dest==dest[_n-1] & other_exporter==0)
reg entry mkt_spec_exp if dest==8 // Average entry rate in Angola without manager with experience 4.0%, with manager 5.9% (difference significant at 1%)

// Prepare Samples
//use MMT_trade_status_entryb_s1.dta, clear
keep if ano>=1997 & ano<=2005
keep if dest==8 | dest==9 | dest==10 | dest==11 | dest==12 | dest==13 | dest==14
xtset empresa_time dest
save data_excol_sal2,replace
keep if dest==8
xtset empresa ano
save data_ang_sal2,replace
keep empresa ano
save dataset_ang_sal2,replace


// Locals
local instruct "tex(pretty frag) tdec(3) rdec(3) auto(3) bdec(3) sdec(3) symbol($^a$,$^b$,$^c$) se label  e(N) nocons"
local ctr_exp_mf = "relsize relapp_lbprod ln_firmage foreign lnod sh_skilled sh_skilled_d relmean_age relsd_age relmean_educ relsd_educ"
local y "y1999 y2000 y2002 y2003 y2004 y2005"
local inta2002 "inta_bf2002"
local inta "inta2002 inta2003 inta2004 inta2005"
local inta_sim "inta20023 inta20045"
local linta_sim "linta20023 linta20045"
local l2inta_sim "l2inta20023 l2inta20045"
local l3inta_sim "l3inta20023 l3inta20045"
local linta "linta2002 linta2003 linta2004 linta2005"
local linta2002 "linta_bf2002"
local linta2002_ang "linta_bf2002_ang"

local inta22002 "inta_bf22002"
local inta2 "inta22002 inta22003 inta22004 inta22005"
local inta2_sim "inta220023 inta220045"
local linta2_sim "linta220023 linta220045"
local l2inta2_sim "l2inta220023 l2inta220045"
local l3inta2_sim "l3inta220023 l3inta220045"
local linta2 "linta22002 linta22003 linta22004 linta22005"
local linta22002 "linta_bf22002"
local linta22002_ang "linta_bf22002_ang"

local y_ang "y1998_ang y1999_ang y2000_ang y2002_ang y2003_ang y2004_ang y2005_ang"
local inta_ang "inta2002_ang inta2003_ang inta2004_ang inta2005_ang"
local linta_ang "linta2002_ang linta2003_ang linta2004_ang linta2005_ang"
local l2inta "l2inta2002 l2inta2003 l2inta2004 l2inta2005"
local l2inta2002 "l2inta_bf2002"
local l2inta2002_ang "l2inta_bf2002_ang"
local l2inta_ang "l2inta2002_ang l2inta2003_ang l2inta2004_ang l2inta2005_ang"
local l3inta "l3inta2002 l3inta2003 l3inta2004 l3inta2005"
local l3inta2002 "l3inta_bf2002"
local l3inta2002_ang "l3inta_bf2002_ang"
local l3inta_ang "l3inta2002_ang l3inta2003_ang l3inta2004_ang l3inta2005_ang"

local inta2_ang "inta22002_ang inta22003_ang inta22004_ang inta22005_ang"
local linta2_ang "linta22002_ang linta22003_ang linta22004_ang linta22005_ang"
local l2inta2 "l2inta22002 l2inta22003 l2inta22004 l2inta22005"
local l2inta22002 "l2inta_bf22002"
local l2inta22002_ang "l2inta_bf22002_ang"
local l2inta2_ang "l2inta22002_ang l2inta22003_ang l2inta22004_ang l2inta22005_ang"
local l3inta2 "l3inta22002 l3inta22003 l3inta22004 l3inta22005"
local l3inta22002 "l3inta_bf22002"
local l3inta22002_ang "l3inta_bf22002_ang"
local l3inta2_ang "l3inta22002_ang l3inta22003_ang l3inta22004_ang l3inta22005_ang"


local winta2002 "winta_bf2002"
local winta "winta2002 winta2003 winta2004 winta2005"
local lwinta "lwinta2002 lwinta2003 lwinta2004 lwinta2005"
local l2winta "l2winta2002 l2winta2003 l2winta2004 l2winta2005"
local l3winta "l3winta2002 l3winta2003 l3winta2004 l3winta2005"
local inta2002_ang "inta_bf2002_ang"
local inta22002_ang "inta_bf22002_ang"

cd "`path'/results"


// A. Destination experience

// Full-history experience

// A1. Having a manager with export experience to Angola
use "`path'/computation/data_ang_sal2.dta",clear
keep if ano>=1998 & ano<=2005
reg entry mkt_spec_exp mkt_spec_exp2 `y' `ctr_exp_mf' i.nace,  vce(cluster empresa)
estat summarize
outreg2 using tables/table1dw_ba_sal2.xls, ctitle(OLS) addtext("Firm-time controls", X, "Year FE", X, "Industry FE", X, "Estimation Method", "OLS") `instruct' replace keep(mkt_spec_exp mkt_spec_exp2) 
outreg2 using tables/table1dw_ctr_ba_sal2.xls, ctitle(OLS) `instruct' replace keep(`ctr_exp_mf' `y')

use "`path'/computation/data_ang_sal2.dta",clear
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample_sal2.dta"
keep if _merge==3
drop _merge
reg entry_bs mkt_spec_exp mkt_spec_exp2 `y' `ctr_exp_mf' i.nace,  vce(cluster empresa)
estat summarize
outreg2 using tables/table1dw_bsample_ba_sal2.xls, ctitle(OLS) addtext("Firm-time controls", X, "Year FE", X, "Industry FE", X, "Estimation Method", "OLS") `instruct' replace keep(mkt_spec_exp mkt_spec_exp2) 
outreg2 using tables/table1dw_ctr_bsample_ba_sal2.xls, ctitle(OLS) `instruct' replace keep(`ctr_exp_mf' `y')

// A2. Placebo: effect of export experience before the end of the war
use "`path'/computation/data_ang_sal2.dta",clear
keep if ano>=1998 & ano<=2005
reghdfe entry mkt_spec_exp mkt_spec_exp2 `y' `inta' `inta2' `ctr_exp_mf', absorb(empresa) vce(cluster empresa) tol(0.001)
outreg2 using tables/table1dw_ba_sal2.xls, ctitle("Placebo") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp mkt_spec_exp2 `inta' `inta2') 
outreg2 using tables/table1dw_ctr_ba_sal2.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

use "`path'/computation/data_ang_sal2.dta",clear
keep if ano>=1998 & ano<=2005
reghdfe entry mkt_spec_exp mkt_spec_exp2 `y' `inta2002' `inta22002' `ctr_exp_mf', absorb(empresa) vce(cluster empresa) tol(0.001)
outreg2 using tables/table1dw_ba_sal2.xls, ctitle("Placebo") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp mkt_spec_exp2 `inta2002' `inta22002') 
outreg2 using tables/table1dw_ctr_ba_sal2.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

use "`path'/computation/data_ang_sal2.dta",clear
keep if ano>=1998 & ano<=2005
reg entry mkt_spec_exp mkt_spec_exp2 `y' `inta' `inta2' `ctr_exp_mf', vce(cluster empresa)
outreg2 using tables/table1dw_ba_sal2.xls, ctitle("Placebo") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta' `inta2') 
outreg2 using tables/table1dw_ctr_ba_sal2.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

use "`path'/computation/data_ang_sal2.dta",clear
keep if ano>=1998 & ano<=2005
reg entry mkt_spec_exp mkt_spec_exp2 `y' `inta2002' `inta22002' `ctr_exp_mf', vce(cluster empresa)
outreg2 using tables/table1dw_ba_sal2.xls, ctitle("Placebo") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta2002' `inta22002') 
outreg2 using tables/table1dw_ctr_ba_sal2.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

use "`path'/computation/data_ang_sal2.dta",clear
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample_sal2.dta"
keep if _merge==3
drop _merge
reghdfe entry_bs mkt_spec_exp mkt_spec_exp2 `y' `inta' `inta2' `ctr_exp_mf', absorb(empresa) vce(cluster empresa) tol(0.001)
outreg2 using tables/table1dw_bsample_ba_sal2.xls, ctitle("Placebo") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta' `inta2') 
outreg2 using tables/table1dw_ctr_bsample_ba_sal2.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

use "`path'/computation/data_ang_sal2.dta",clear
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample_sal2.dta"
keep if _merge==3
drop _merge
reghdfe entry_bs mkt_spec_exp mkt_spec_exp2 `y' `inta2002' `inta22002' `ctr_exp_mf', absorb(empresa) vce(cluster empresa) tol(0.001)
outreg2 using tables/table1dw_bsample_ba_sal2.xls, ctitle("Placebo") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta2002' `inta22002') 
outreg2 using tables/table1dw_ctr_bsample_ba_sal2.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

use "`path'/computation/data_ang_sal2.dta",clear
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample_sal2.dta"
keep if _merge==3
drop _merge
reg entry_bs mkt_spec_exp mkt_spec_exp2 `y' `inta' `inta2' `ctr_exp_mf', vce(cluster empresa)
outreg2 using tables/table1dw_bsample_ba_sal2.xls, ctitle("Placebo") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta' `inta2') 
outreg2 using tables/table1dw_ctr_bsample_ba_sal2.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

use "`path'/computation/data_ang_sal2.dta",clear
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample_sal2.dta"
keep if _merge==3
drop _merge
reg entry_bs mkt_spec_exp mkt_spec_exp2 `y' `inta2002' `inta22002' `ctr_exp_mf', vce(cluster empresa)
outreg2 using tables/table1dw_bsample_ba_sal2.xls, ctitle("Placebo") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta2002' `inta22002') 
outreg2 using tables/table1dw_ctr_bsample_ba_sal2.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize



///////////////////////////////////////////////////////
//  Step 7. Regressions without firm-time controls   //
///////////////////////////////////////////////////////


/////////////////////////////////////
//////////// Regressions ////////////
/////////////////////////////////////

// Locals
local instruct "tex(pretty frag) tdec(3) rdec(3) auto(3) bdec(3) sdec(3) symbol($^a$,$^b$,$^c$) se label  e(N) nocons"
local ctr_exp_mf = "relsize relapp_lbprod ln_firmage foreign lnod sh_skilled sh_skilled_d relmean_age relsd_age relmean_educ relsd_educ"
local y "y1999 y2000 y2002 y2003 y2004 y2005"
local inta2002 "inta_bf2002"
local inta "inta2002 inta2003 inta2004 inta2005"
local inta_sim "inta20023 inta20045"
local linta_sim "linta20023 linta20045"
local l2inta_sim "l2inta20023 l2inta20045"
local l3inta_sim "l3inta20023 l3inta20045"
local linta "linta2002 linta2003 linta2004 linta2005"
local linta2002 "linta_bf2002"
local linta2002_ang "linta_bf2002_ang"
local y_ang "y1998_ang y1999_ang y2000_ang y2002_ang y2003_ang y2004_ang y2005_ang"
local inta_ang "inta2002_ang inta2003_ang inta2004_ang inta2005_ang"
local linta_ang "linta2002_ang linta2003_ang linta2004_ang linta2005_ang"
local l2inta "l2inta2002 l2inta2003 l2inta2004 l2inta2005"
local l2inta2002 "l2inta_bf2002"
local l2inta2002_ang "l2inta_bf2002_ang"
local l2inta_ang "l2inta2002_ang l2inta2003_ang l2inta2004_ang l2inta2005_ang"
local l3inta "l3inta2002 l3inta2003 l3inta2004 l3inta2005"
local l3inta2002 "l3inta_bf2002"
local l3inta2002_ang "l3inta_bf2002_ang"
local l3inta_ang "l3inta2002_ang l3inta2003_ang l3inta2004_ang l3inta2005_ang"
local winta2002 "winta_bf2002"
local winta "winta2002 winta2003 winta2004 winta2005"
local lwinta "lwinta2002 lwinta2003 lwinta2004 lwinta2005"
local l2winta "l2winta2002 l2winta2003 l2winta2004 l2winta2005"
local l3winta "l3winta2002 l3winta2003 l3winta2004 l3winta2005"
local inta2002_ang "inta_bf2002_ang"

cd "`path'/results"


// A. Destination experience
////////////////////////////

// Full-history experience

// A1. Having a manager with export experience to Angola

// Regular sample
use "`path'/computation/data_ang.dta",clear
keep if ano>=1998 & ano<=2005
reg entry mkt_spec_exp `y'  i.nace,  vce(cluster empresa)
estat summarize
outreg2 using tables/table1dw_ba_no.xls, ctitle(OLS) addtext("Firm-time controls", X, "Year FE", X, "Industry FE", X, "Estimation Method", "OLS") `instruct' replace keep(mkt_spec_exp) 
outreg2 using tables/table1dw_ctr_ba_no.xls, ctitle(OLS) `instruct' replace keep(`ctr_exp_mf' `y')

// Balanced sample
use "`path'/computation/data_ang.dta",clear
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
reg entry_bs mkt_spec_exp `y'  i.nace,  vce(cluster empresa)
estat summarize
outreg2 using tables/table1dw_bsample_ba_no.xls, ctitle(OLS) addtext("Firm-time controls", X, "Year FE", X, "Industry FE", X, "Estimation Method", "OLS") `instruct' replace keep(mkt_spec_exp) 
outreg2 using tables/table1dw_ctr_bsample_ba_no.xls, ctitle(OLS) `instruct' replace keep(`ctr_exp_mf' `y')


// A2. Placebo: effect of export experience before the end of the war

// Regular sample
	// Dynamic diff-in-diff, with firm fixed effects
use "`path'/computation/data_ang.dta",clear
keep if ano>=1998 & ano<=2005
reghdfe entry mkt_spec_exp `y' `inta' , absorb(empresa) vce(cluster empresa) tol(0.001)
outreg2 using tables/table1dw_ba_no.xls, ctitle("Placebo") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_ba_no.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Diff-in-diff, with firm fixed effects
use "`path'/computation/data_ang.dta",clear
keep if ano>=1998 & ano<=2005
reghdfe entry mkt_spec_exp `y' `inta2002' , absorb(empresa) vce(cluster empresa) tol(0.001)
outreg2 using tables/table1dw_ba_no.xls, ctitle("Placebo") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_ba_no.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Dynamic diff-in-diff, without firm fixed effects
use "`path'/computation/data_ang.dta",clear
keep if ano>=1998 & ano<=2005
reg entry mkt_spec_exp `y' `inta' , vce(cluster empresa)
outreg2 using tables/table1dw_ba_no.xls, ctitle("Placebo") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_ba_no.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Diff-in-diff, without firm fixed effects
use "`path'/computation/data_ang.dta",clear
keep if ano>=1998 & ano<=2005
reg entry mkt_spec_exp `y' `inta2002' , vce(cluster empresa)
outreg2 using tables/table1dw_ba_no.xls, ctitle("Placebo") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_ba_no.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

// Balanced sample
	// Dynamic diff-in-diff, with firm fixed effects
use "`path'/computation/data_ang.dta",clear
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
reghdfe entry_bs mkt_spec_exp `y' `inta' , absorb(empresa) vce(cluster empresa) tol(0.001)
outreg2 using tables/table1dw_bsample_ba_no.xls, ctitle("Placebo") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_bsample_ba_no.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Diff-in-diff, with firm fixed effects
use "`path'/computation/data_ang.dta",clear
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
reghdfe entry_bs mkt_spec_exp `y' `inta2002' , absorb(empresa) vce(cluster empresa) tol(0.001)
outreg2 using tables/table1dw_bsample_ba_no.xls, ctitle("Placebo") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_bsample_ba_no.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Dynamic diff-in-diff, without firm fixed effects
use "`path'/computation/data_ang.dta",clear
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
reg entry_bs mkt_spec_exp `y' `inta' , vce(cluster empresa)
outreg2 using tables/table1dw_bsample_ba_no.xls, ctitle("Placebo") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_bsample_ba_no.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Diff-in-diff, without firm fixed effects
use "`path'/computation/data_ang.dta",clear
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
reg entry_bs mkt_spec_exp `y' `inta2002' , vce(cluster empresa)
outreg2 using tables/table1dw_bsample_ba_no.xls, ctitle("Placebo") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "OLS") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_bsample_ba_no.xls, ctitle("Placebo") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize



// A3. Placebo: IV

// Regular sample
	// Dynamic diff-in-diff, with firm fixed effects
use "`path'/computation/data_ang.dta",clear
keep if ano>=1998 & ano<=2005
xtivreg2 entry (mkt_spec_exp `inta' = l3mkt_spec_exp `l3inta' l2mkt_spec_exp `l2inta' lmkt_spec_exp `linta') y1999 y2000 y2002 y2003 y2004 y2005 ,fe  cluster(empresa) first
outreg2 using tables/table1dw_ba_no.xls, ctitle("Placebo IV") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_ba_no.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Diff-in-diff, with firm fixed effects
use "`path'/computation/data_ang.dta",clear
keep if ano>=1998 & ano<=2005
su entry mkt_spec_exp `inta2002'  l3mkt_spec_exp `l3inta' l2mkt_spec_exp `l2inta' lmkt_spec_exp `linta' y1999 y2000 y2002 y2003 y2004 y2005  if ano==2002
xtivreg2 entry (mkt_spec_exp `inta2002' = l3mkt_spec_exp `l3inta2002' l2mkt_spec_exp `l2inta2002' lmkt_spec_exp `linta2002') y1999 y2000 y2002 y2003 y2004 y2005 ,fe  cluster(empresa) first partial(y1999 y2000 y2002 y2003 y2004 y2005)
outreg2 using tables/table1dw_ba_no.xls, ctitle("Placebo IV") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_ba_no.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Dynamic diff-in-diff, without firm fixed effects
use "`path'/computation/data_ang.dta",clear
keep if ano>=1998 & ano<=2005
ivreg2 entry (mkt_spec_exp `inta' = l3mkt_spec_exp `l3inta' l2mkt_spec_exp `l2inta' lmkt_spec_exp `linta') y1999 y2000 y2002 y2003 y2004 y2005 ,  cluster(empresa) first
outreg2 using tables/table1dw_ba_no.xls, ctitle("Placebo IV") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_ba_no.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Diff-in-diff, without firm fixed effects
use "`path'/computation/data_ang.dta",clear
keep if ano>=1998 & ano<=2005
ivreg2 entry (mkt_spec_exp `inta2002' = l3mkt_spec_exp `l3inta2002' l2mkt_spec_exp `l2inta2002' lmkt_spec_exp `linta2002') y1999 y2000 y2002 y2003 y2004 y2005 ,  cluster(empresa) first
outreg2 using tables/table1dw_ba_no.xls, ctitle("Placebo IV") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_ba_no.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Simplified dynamic diff-in-diff, with firm fixed effects
use "`path'/computation/data_ang.dta",clear
keep if ano>=1998 & ano<=2005
xtivreg2 entry (mkt_spec_exp `inta_sim' = l3mkt_spec_exp `l3inta_sim' l2mkt_spec_exp `l2inta_sim' lmkt_spec_exp `linta_sim') y1999 y2000 y2002 y2003 y2004 y2005 ,fe  cluster(empresa) first
outreg2 using tables/table1dw_ba_sim_no.xls, ctitle("Placebo IV 2") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta_sim') 
outreg2 using tables/table1dw_ctr_ba_sim_no.xls, ctitle("Placebo IV 2") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Simplified dynamic diff-in-diff, without firm fixed effects
use "`path'/computation/data_ang.dta",clear
keep if ano>=1998 & ano<=2005
ivreg2 entry (mkt_spec_exp `inta_sim' = l3mkt_spec_exp `l3inta_sim' l2mkt_spec_exp `l2inta_sim' lmkt_spec_exp `linta_sim') y1999 y2000 y2002 y2003 y2004 y2005 ,  cluster(empresa) first
outreg2 using tables/table1dw_ba_sim_no.xls, ctitle("Placebo IV 2") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta_sim') 
outreg2 using tables/table1dw_ctr_ba_sim_no.xls, ctitle("Placebo IV 2") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize

// Balanced sample
	// Dynamic diff-in-diff, with firm fixed effects
use "`path'/computation/data_ang.dta",clear
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
xtivreg2 entry_bs (mkt_spec_exp `inta' = l3mkt_spec_exp `l3inta' l2mkt_spec_exp `l2inta' lmkt_spec_exp `linta') y1999 y2000 y2002 y2003 y2004 y2005 ,fe  cluster(empresa) first
outreg2 using tables/table1dw_bsample_ba_no.xls, ctitle("Placebo IV") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_bsample_ba_no.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Diff-in-diff, with firm fixed effects
use "`path'/computation/data_ang.dta",clear
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
xtivreg2 entry_bs (mkt_spec_exp `inta2002' = l3mkt_spec_exp `l3inta2002' l2mkt_spec_exp `l2inta2002' lmkt_spec_exp `linta2002') y1999 y2000 y2002 y2003 y2004 y2005 ,fe  cluster(empresa) first
outreg2 using tables/table1dw_bsample_ba_no.xls, ctitle("Placebo IV") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_bsample_ba_no.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Dynamic diff-in-diff, without firm fixed effects
use "`path'/computation/data_ang.dta",clear
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
ivreg2 entry_bs (mkt_spec_exp `inta' = l3mkt_spec_exp `l3inta' l2mkt_spec_exp `l2inta' lmkt_spec_exp `linta') y1999 y2000 y2002 y2003 y2004 y2005 ,  cluster(empresa) first
outreg2 using tables/table1dw_bsample_ba_no.xls, ctitle("Placebo IV") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta') 
outreg2 using tables/table1dw_ctr_bsample_ba_no.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Diff-in-diff, without firm fixed effects
use "`path'/computation/data_ang.dta",clear
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
ivreg2 entry_bs (mkt_spec_exp `inta2002' = l3mkt_spec_exp `l3inta2002' l2mkt_spec_exp `l2inta2002' lmkt_spec_exp `linta2002') y1999 y2000 y2002 y2003 y2004 y2005 ,  cluster(empresa) first
outreg2 using tables/table1dw_bsample_ba_no.xls, ctitle("Placebo IV") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta2002') 
outreg2 using tables/table1dw_ctr_bsample_ba_no.xls, ctitle("Placebo IV") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Simplified dynamic diff-in-diff, with firm fixed effects
use "`path'/computation/data_ang.dta",clear
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
xtivreg2 entry_bs (mkt_spec_exp `inta_sim' = l3mkt_spec_exp `l3inta_sim' l2mkt_spec_exp `l2inta_sim' lmkt_spec_exp `linta_sim') y1999 y2000 y2002 y2003 y2004 y2005 ,fe  cluster(empresa) first
outreg2 using tables/table1dw_bsample_ba_sim_no.xls, ctitle("Placebo IV 2") addtext("Firm-time controls", X,"Firm FE", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta_sim') 
outreg2 using tables/table1dw_ctr_bsample_ba_sim_no.xls, ctitle("Placebo IV 2") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize
	// Simplified dynamic diff-in-diff, without firm fixed effects
use "`path'/computation/data_ang.dta",clear
keep if ano>=1998 & ano<=2005
sort empresa
merge empresa using "`path'/computation/bsample.dta"
keep if _merge==3
drop _merge
ivreg2 entry_bs (mkt_spec_exp `inta_sim' = l3mkt_spec_exp `l3inta_sim' l2mkt_spec_exp `l2inta_sim' lmkt_spec_exp `linta_sim') y1999 y2000 y2002 y2003 y2004 y2005 ,  cluster(empresa) first
outreg2 using tables/table1dw_bsample_ba_sim_no.xls, ctitle("Placebo IV 2") addtext("Firm-time controls", X, "Year FE", X, "Estimation Method", "IV") `instruct' append keep(mkt_spec_exp `inta_sim') 
outreg2 using tables/table1dw_ctr_bsample_ba_sim_no.xls, ctitle("Placebo IV 2") `instruct' append keep(`ctr_exp_mf' `y')
estat summarize


log close
